diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-10 16:32:35 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-10 16:32:51 +0200 |
commit | 5a794bb1827d1bf603de08df25684a4d77096b20 (patch) | |
tree | 085f34708e0c234fa419dace2c6595f75c66cd20 | |
parent | e68a0b4707885be3c016f3b4f9443740e5dcc25b (diff) | |
download | re-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.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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)) { |