summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2023-05-06 11:22:22 +0100
committerPádraig Brady <P@draigBrady.com>2023-05-06 11:26:04 +0100
commitfae65623a92a3f150fd35cfef58dcb3d8533f94c (patch)
tree5b07d7b17c2990a93b6258602277d167a4be6eb2
parent300af7869161a3618e28cbae3daefc25c8267efe (diff)
downloadcoreutils-fae65623a92a3f150fd35cfef58dcb3d8533f94c.tar.gz
pr: fix parsing of empty arguments
Before: $ pr --expand-tabs= pr: '-e' extra characters or invalid number in the argument: ‘SHELL=/bin/bash’: Value too large for defined data type After: $ pr --expand-tabs= pr: '-e': Invalid argument: ‘’ * src/pr.c (getoptarg): Ensure we don't parse beyond the end of an empty argument, thus outputting arbitrary stack info in subsequent error messages. Addresses https://bugs.debian.org/1035596
-rw-r--r--src/pr.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/pr.c b/src/pr.c
index 14a368b6c..1c32e8c81 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -1168,6 +1168,12 @@ getoptnum (char const *n_str, int min, int *num, char const *err)
static void
getoptarg (char *arg, char switch_char, char *character, int *number)
{
+ if (!*arg)
+ {
+ error (0, 0, _("'-%c': Invalid argument: %s"), switch_char, quote (arg));
+ usage (EXIT_FAILURE);
+ }
+
if (!ISDIGIT (*arg))
*character = *arg++;
if (*arg)