aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-10 16:32:35 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-10 16:32:51 +0200
commit5a794bb1827d1bf603de08df25684a4d77096b20 (patch)
tree085f34708e0c234fa419dace2c6595f75c66cd20
parente68a0b4707885be3c016f3b4f9443740e5dcc25b (diff)
downloadre-name-5a794bb1827d1bf603de08df25684a4d77096b20.tar.gz
re.c: Ensure no file name contains newline
Otherwise, the operation is broken, as it depends on reading file names separated by newlines.
-rw-r--r--re.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/re.c b/re.c
index 07b6846..c4490b3 100644
--- a/re.c
+++ b/re.c
@@ -5,7 +5,7 @@
int
main(int argc, char *argv[])
{
- char ans[10], file[30];
+ char *a, ans[10], file[30];
FILE *fp;
int i;
@@ -14,6 +14,17 @@ main(int argc, char *argv[])
return 1;
}
+ /* Ensure arguments do not contain newlines. */
+ for (i = 1; i < argc; i++)
+ for (a = argv[i]; *a; a++)
+ if (*a == '\n') {
+ *a = '*';
+ fprintf(stderr,
+ "%s contains newline (at *)\n",
+ argv[i]);
+ return 1;
+ }
+
sprintf(file, "/var/tmp/re.%d", getppid());
if (!access(file, F_OK)) {