diff options
author | Pádraig Brady <P@draigBrady.com> | 2015-10-27 13:13:59 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2015-10-27 17:24:54 +0000 |
commit | 6796698c9945d87236ffcc939137d0919ef04931 (patch) | |
tree | dd843e7808186887c2959451e34fdd7f42783359 /src/sum.c | |
parent | 106d4bf159a97b573d6479473fa38216fb8bfada (diff) | |
download | coreutils-6796698c9945d87236ffcc939137d0919ef04931.tar.xz |
all: quote string arguments in error messages
These strings are often file names or other user specified
parameters, which can give confusing errors in
the presence of unexpected characters for example.
* cfg.mk (sc_error_quotes): A new syntax check rule.
* src/*.c: Wrap error() string arguments with quote().
* tests/: Adjust accordingly.
* NEWS: Mention the improvement.
Diffstat (limited to 'src/sum.c')
-rw-r--r-- | src/sum.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -27,6 +27,7 @@ #include "error.h" #include "fadvise.h" #include "human.h" +#include "quote.h" #include "safe-read.h" #include "xfreopen.h" @@ -105,7 +106,7 @@ bsd_sum_file (const char *file, int print_name) fp = fopen (file, (O_BINARY ? "rb" : "r")); if (fp == NULL) { - error (0, errno, "%s", file); + error (0, errno, "%s", quote (file)); return false; } } @@ -122,7 +123,7 @@ bsd_sum_file (const char *file, int print_name) if (ferror (fp)) { - error (0, errno, "%s", file); + error (0, errno, "%s", quote (file)); if (!is_stdin) fclose (fp); return false; @@ -130,7 +131,7 @@ bsd_sum_file (const char *file, int print_name) if (!is_stdin && fclose (fp) != 0) { - error (0, errno, "%s", file); + error (0, errno, "%s", quote (file)); return false; } @@ -175,7 +176,7 @@ sysv_sum_file (const char *file, int print_name) fd = open (file, O_RDONLY | O_BINARY); if (fd == -1) { - error (0, errno, "%s", file); + error (0, errno, "%s", quote (file)); return false; } } @@ -190,7 +191,7 @@ sysv_sum_file (const char *file, int print_name) if (bytes_read == SAFE_READ_ERROR) { - error (0, errno, "%s", file); + error (0, errno, "%s", quote (file)); if (!is_stdin) close (fd); return false; @@ -203,7 +204,7 @@ sysv_sum_file (const char *file, int print_name) if (!is_stdin && close (fd) != 0) { - error (0, errno, "%s", file); + error (0, errno, "%s", quote (file)); return false; } @@ -270,6 +271,6 @@ main (int argc, char **argv) ok &= sum_func (argv[optind], files_given); if (have_read_stdin && fclose (stdin) == EOF) - error (EXIT_FAILURE, errno, "-"); + error (EXIT_FAILURE, errno, "%s", quote ("-")); return ok ? EXIT_SUCCESS : EXIT_FAILURE; } |