From 5a794bb1827d1bf603de08df25684a4d77096b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 10 Jul 2021 16:32:35 +0200 Subject: re.c: Ensure no file name contains newline Otherwise, the operation is broken, as it depends on reading file names separated by newlines. --- re.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 're.c') 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)) { -- cgit v1.2.3