Subject: Bug#1035596: coreutils: pr: --number-lines= yields "extra characters or invalid number in the argument: ‘SHELL=/bin/bash’: ERANGE"

From: Pádraig Brady <[email-masked]>
Date: Sat, 6 May 2023 11:31:46 +0100

On 06/05/2023 01:19, наб wrote:
> Package: coreutils
> Version: 8.32-4+b1
> Version: 9.1-1
> Severity: normal
> Dear Maintainer,
> :v

Fixed upstream with the attached.

cheers,
Pádraig
From fae65623a92a3f150fd35cfef58dcb3d8533f94c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Sat, 6 May 2023 11:22:22 +0100
Subject: [PATCH] pr: fix parsing of empty arguments
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 | 6 ++++++
 1 file changed, 6 insertions(+)

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)
-- 
2.26.2