]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
pr: fix parsing of empty arguments
authorPádraig Brady <P@draigBrady.com>
Sat, 6 May 2023 10:22:22 +0000 (11:22 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 6 May 2023 10:26:04 +0000 (11:26 +0100)
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

src/pr.c

index 14a368b6c9ce8f38781ad5943d3d91ee510e3917..1c32e8c81d25bfd0ba3bd29e864ccd317860e90a 100644 (file)
--- 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)