From 6796698c9945d87236ffcc939137d0919ef04931 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 27 Oct 2015 13:13:59 +0000 Subject: 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. --- src/stty.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/stty.c') diff --git a/src/stty.c b/src/stty.c index c0057f2d7..2ed3939d5 100644 --- a/src/stty.c +++ b/src/stty.c @@ -1169,17 +1169,17 @@ main (int argc, char **argv) int fdflags; device_name = file_name; if (fd_reopen (STDIN_FILENO, device_name, O_RDONLY | O_NONBLOCK, 0) < 0) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); if ((fdflags = fcntl (STDIN_FILENO, F_GETFL)) == -1 || fcntl (STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0) error (EXIT_FAILURE, errno, _("%s: couldn't reset non-blocking mode"), - device_name); + quote (device_name)); } else device_name = _("standard input"); if (tcgetattr (STDIN_FILENO, &mode)) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); if (verbose_output || recoverable_output || noargs) { @@ -1281,7 +1281,7 @@ main (int argc, char **argv) if (ioctl (STDIN_FILENO, TIOCEXT, &val) != 0) { error (EXIT_FAILURE, errno, _("%s: error setting %s"), - device_name, quote (arg)); + quote_n (0, device_name), quote_n (1, arg)); } } #endif @@ -1362,7 +1362,7 @@ main (int argc, char **argv) static struct termios new_mode; if (tcsetattr (STDIN_FILENO, TCSADRAIN, &mode)) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); /* POSIX (according to Zlotnick's book) tcsetattr returns zero if it performs *any* of the requested operations. This means it @@ -1372,7 +1372,7 @@ main (int argc, char **argv) compare them to the requested ones. */ if (tcgetattr (STDIN_FILENO, &new_mode)) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); /* Normally, one shouldn't use memcmp to compare structures that may have 'holes' containing uninitialized data, but we have been @@ -1399,7 +1399,7 @@ main (int argc, char **argv) { error (EXIT_FAILURE, 0, _("%s: unable to perform all requested operations"), - device_name); + quote (device_name)); #ifdef TESTING { size_t i; @@ -1679,7 +1679,7 @@ set_window_size (int rows, int cols, char const *device_name) if (get_win_size (STDIN_FILENO, &win)) { if (errno != EINVAL) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); memset (&win, 0, sizeof (win)); } @@ -1721,16 +1721,16 @@ set_window_size (int rows, int cols, char const *device_name) win.ws_col = 1; if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win)) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); if (ioctl (STDIN_FILENO, TIOCSSIZE, (char *) &ttysz)) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); return; } # endif if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win)) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); } static void @@ -1741,10 +1741,11 @@ display_window_size (bool fancy, char const *device_name) if (get_win_size (STDIN_FILENO, &win)) { if (errno != EINVAL) - error (EXIT_FAILURE, errno, "%s", device_name); + error (EXIT_FAILURE, errno, "%s", quote (device_name)); if (!fancy) error (EXIT_FAILURE, 0, - _("%s: no size information for this device"), device_name); + _("%s: no size information for this device"), + quote (device_name)); } else { -- cgit v1.2.3-54-g00ecf