From MAILER-DAEMON Tue Aug 27 18:07:08 2019
Received: from list by lists.gnu.org with archive (Exim 4.90_1)
	id 1i2jcK-0002Es-0Y
	for mharc-bug-diffutils@gnu.org; Tue, 27 Aug 2019 18:07:08 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:39875)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2jcH-0002E9-6a
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 18:07:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2jcG-0005Ed-81
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 18:07:05 -0400
Received: from debbugs.gnu.org ([209.51.188.43]:40703)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1i2jcG-0005ET-1g
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 18:07:04 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2jcD-0002L6-TH
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 18:07:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 27 Aug 2019 22:07:01 +0000
Resent-Message-ID: <handler.34519.B34519.15669435908929@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 34519
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Santiago Vila <sanvila@unex.es>
Cc: 34519@debbugs.gnu.org
Received: via spool by 34519-submit@debbugs.gnu.org id=B34519.15669435908929
 (code B ref 34519); Tue, 27 Aug 2019 22:07:01 +0000
Received: (at 34519) by debbugs.gnu.org; 27 Aug 2019 22:06:30 +0000
Received: from localhost ([127.0.0.1]:49521 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1i2jbi-0002Jx-Lj
 for submit@debbugs.gnu.org; Tue, 27 Aug 2019 18:06:30 -0400
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:44074)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eggert@cs.ucla.edu>) id 1i2jbh-0002Je-8Q
 for 34519@debbugs.gnu.org; Tue, 27 Aug 2019 18:06:29 -0400
Received: from localhost (localhost [127.0.0.1])
 by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0DC831600C6;
 Tue, 27 Aug 2019 15:06:23 -0700 (PDT)
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
 by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id 1jNtzTejMUDM; Tue, 27 Aug 2019 15:06:22 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
 by zimbra.cs.ucla.edu (Postfix) with ESMTP id 55D7B1600EC;
 Tue, 27 Aug 2019 15:06:22 -0700 (PDT)
X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
 by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id PjQDHj2MUIsx; Tue, 27 Aug 2019 15:06:22 -0700 (PDT)
Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com
 [23.242.74.103])
 by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 2CCA41600C6;
 Tue, 27 Aug 2019 15:06:22 -0700 (PDT)
References: <alpine.DEB.2.20.1902180147100.13056@tulipan.isla-invisible.es>
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
Message-ID: <588c7101-5d51-78f1-e79c-f89c69c3b804@cs.ucla.edu>
Date: Tue, 27 Aug 2019 15:06:21 -0700
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.8.0
MIME-Version: 1.0
In-Reply-To: <alpine.DEB.2.20.1902180147100.13056@tulipan.isla-invisible.es>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 209.51.188.43
Subject: [bug-diffutils] bug#34519: bug#34519: Test "colors" fails on
 Debian/ppc64el
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
 <mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
 <mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 27 Aug 2019 22:07:06 -0000

Santiago Vila wrote:
> In tests/colors there was a race condition which I tried to fix
> by adding a "sleep 1", like this:
> 
> mkfifo fifo
> printf '%1000000s-a' > a
> printf '%1000000s-b' > b
> head -c 10 < fifo > /dev/null &
> sleep 1
> diff --color=always ---presume-output-tty a b > fifo
> test $? = 141 || fail=1

Sorry, but what is the race condition, and why would adding 'sleep 1' help? The 
test should work regardless of whether 'diff' starts before 'head' does.

Are fifos broken on your system somehow?

Can you use 'strace -f' to see what syscalls are going wrong in 'head' and/or 
'diff'?




From MAILER-DAEMON Tue Aug 27 19:24:08 2019
Received: from list by lists.gnu.org with archive (Exim 4.90_1)
	id 1i2koq-0004t5-9y
	for mharc-bug-diffutils@gnu.org; Tue, 27 Aug 2019 19:24:08 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:50199)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2kom-0004ss-IW
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 19:24:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2kok-0002eV-R7
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 19:24:04 -0400
Received: from debbugs.gnu.org ([209.51.188.43]:40770)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1i2kok-0002eO-Kw
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 19:24:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2kok-0004aX-GJ
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 19:24:02 -0400
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-To: bug-diffutils@gnu.org
Resent-Date: Tue, 27 Aug 2019 23:24:02 +0000
Resent-Message-ID: <handler.35256.D35256.156694820117575.done@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: cc-closed 35256
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: alec@unifiedmathematics.com
Cc: 35256-done@debbugs.gnu.org
Mail-Followup-To: 35256@debbugs.gnu.org, eggert@cs.ucla.edu,
 alec@unifiedmathematics.com
Received: via spool by 35256-done@debbugs.gnu.org id=D35256.156694820117575
 (code D ref 35256); Tue, 27 Aug 2019 23:24:02 +0000
Received: (at 35256-done) by debbugs.gnu.org; 27 Aug 2019 23:23:21 +0000
Received: from localhost ([127.0.0.1]:49589 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1i2ko4-0004ZN-1l
 for submit@debbugs.gnu.org; Tue, 27 Aug 2019 19:23:21 -0400
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55782)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eggert@cs.ucla.edu>) id 1i2ko0-0004Z5-B5
 for 35256-done@debbugs.gnu.org; Tue, 27 Aug 2019 19:23:17 -0400
Received: from localhost (localhost [127.0.0.1])
 by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1F31E1600C6;
 Tue, 27 Aug 2019 16:23:10 -0700 (PDT)
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
 by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id nWAS_25-KzmM; Tue, 27 Aug 2019 16:23:08 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
 by zimbra.cs.ucla.edu (Postfix) with ESMTP id CFD951600EC;
 Tue, 27 Aug 2019 16:23:08 -0700 (PDT)
X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
 by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 9iSi2Sdh4XFr; Tue, 27 Aug 2019 16:23:08 -0700 (PDT)
Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com
 [23.242.74.103])
 by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id A24C31600C6;
 Tue, 27 Aug 2019 16:23:08 -0700 (PDT)
References: <8bbb0482c31d85f7bc37b78824e27c31d51ad479@webmail.unifiedmathematics.com>
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
Message-ID: <14605a16-f1fb-fa44-7314-2092cf44ba75@cs.ucla.edu>
Date: Tue, 27 Aug 2019 16:23:08 -0700
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.8.0
MIME-Version: 1.0
In-Reply-To: <8bbb0482c31d85f7bc37b78824e27c31d51ad479@webmail.unifiedmathematics.com>
Content-Type: multipart/mixed; boundary="------------FB16B5F0F5D1BCC95D18486C"
Content-Language: en-US
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 209.51.188.43
Subject: [bug-diffutils] bug#35256: bug#35256: Bug report for -W argument
 (maximum width) - minor and not dangerous
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
 <mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
 <mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 27 Aug 2019 23:24:06 -0000

This is a multi-part message in MIME format.
--------------FB16B5F0F5D1BCC95D18486C
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

alec@unifiedmathematics.com wrote:

> I know diff is used by A LOT of other programs, some of which are
> web-accessible

I'm afraid that ship sailed a while ago: if you let a remote attacker specify an 
arbitrary option to GNU diff there is lots of other trouble you can get into. 
For example, the -I option lets the attacker specify a regular expression that 
can cause diff to undergo exponential complexity. The general wisdom nowadays is 
to not expose command-line operands to attackers.

As for putting in a limit, the GNU Coding Standards say to not impose arbitrary 
limits. In some cases there are good reasons to impose a limit anyway but this 
one doesn't seem to rise to that level.

You do raise a good point that 'diff' shouldn't treat negative inputs as if they 
were large positive inputs, so I installed the attached patch.

Thanks for reporting the problem; your bug report was a pleasure to read.

--------------FB16B5F0F5D1BCC95D18486C
Content-Type: text/x-patch;
 name="0001-diff-don-t-mistreat-N-in-arg-as-a-large-number.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-diff-don-t-mistreat-N-in-arg-as-a-large-number.patch"

>From 8d26b1403e8607811ccebdfe2822f2dad42a36d3 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 27 Aug 2019 16:14:15 -0700
Subject: [PATCH] =?UTF-8?q?diff:=20don=E2=80=99t=20mistreat=20-N=20in=20ar?=
 =?UTF-8?q?g=20as=20a=20large=20number?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by alec (Bug#35256).
* NEWS: Mention the fix.
* bootstrap.conf (gnulib_modules): Use strtoimax and xstrtoimax,
not strtoumax and strtoumax.
* src/cmp.c (bytes): Now signed, with -1 representing no limit.
All uses changed.
* src/cmp.c (specify_ignore_initial, main):
* src/diff.c (main):
* src/ifdef.c (format_group):
* src/sdiff.c (interact):
Use strtoimax, not strtoumax.
---
 NEWS           |  4 ++++
 bootstrap.conf |  4 ++--
 src/cmp.c      | 27 ++++++++++++++-------------
 src/diff.c     | 14 +++++++-------
 src/ifdef.c    |  6 +++---
 src/sdiff.c    | 10 +++++-----
 6 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/NEWS b/NEWS
index 5c1ae5f..3ecd111 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,10 @@ GNU diffutils NEWS                                    -*- outline -*-
   that was intended for stdin, stdout, or stderr.
   [bug#33965 present since "the beginning"]
 
+  cmp, diff and sdiff no longer treat negative command-line
+  option-arguments as if they were large positive numbers.
+  [bug#35256 introduced in 2.8]
+
 
 * Noteworthy changes in release 3.7 (2018-12-31) [stable]
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 7d5ea62..1a20900 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -70,7 +70,7 @@ stdint
 strcase
 strftime
 strptime
-strtoumax
+strtoimax
 sys_wait
 system-quote
 unistd
@@ -85,7 +85,7 @@ xalloc
 xfreopen
 xreadlink
 xstdopen
-xstrtoumax
+xstrtoimax
 xvasprintf
 '
 
diff --git a/src/cmp.c b/src/cmp.c
index ce2bdb5..16e8869 100644
--- a/src/cmp.c
+++ b/src/cmp.c
@@ -75,8 +75,8 @@ static size_t buf_size;
 /* Initial prefix to ignore for each file.  */
 static off_t ignore_initial[2];
 
-/* Number of bytes to compare.  */
-static uintmax_t bytes = UINTMAX_MAX;
+/* Number of bytes to compare, or -1 if there is no limit.  */
+static intmax_t bytes = -1;
 
 /* Output format.  */
 static enum comparison_type
@@ -129,12 +129,12 @@ static char const valid_suffixes[] = "kKMGTPEZY0";
 static void
 specify_ignore_initial (int f, char **argptr, char delimiter)
 {
-  uintmax_t val;
+  intmax_t val;
   char const *arg = *argptr;
-  strtol_error e = xstrtoumax (arg, argptr, 0, &val, valid_suffixes);
-  if (! (e == LONGINT_OK
-         || (e == LONGINT_INVALID_SUFFIX_CHAR && **argptr == delimiter))
-      || TYPE_MAXIMUM (off_t) < val)
+  strtol_error e = xstrtoimax (arg, argptr, 0, &val, valid_suffixes);
+  if (! ((e == LONGINT_OK
+          || (e == LONGINT_INVALID_SUFFIX_CHAR && **argptr == delimiter))
+         && 0 <= val && val <= TYPE_MAXIMUM (off_t)))
     try_help ("invalid --ignore-initial value '%s'", arg);
   if (ignore_initial[f] < val)
     ignore_initial[f] = val;
@@ -237,10 +237,11 @@ main (int argc, char **argv)
 
       case 'n':
         {
-          uintmax_t n;
-          if (xstrtoumax (optarg, 0, 0, &n, valid_suffixes) != LONGINT_OK)
+          intmax_t n;
+          if (xstrtoimax (optarg, 0, 0, &n, valid_suffixes) != LONGINT_OK
+              || n < 0)
             try_help ("invalid --bytes value '%s'", optarg);
-          if (n < bytes)
+          if (! (0 <= bytes && bytes < n))
             bytes = n;
         }
         break;
@@ -341,7 +342,7 @@ main (int argc, char **argv)
         s0 = 0;
       if (s1 < 0)
         s1 = 0;
-      if (s0 != s1 && MIN (s0, s1) < bytes)
+      if (s0 != s1 && (bytes < 0 || MIN (s0, s1) < bytes))
         exit (EXIT_FAILURE);
     }
 
@@ -379,7 +380,7 @@ cmp (void)
   bool at_line_start = true;
   off_t line_number = 1;	/* Line number (1...) of difference. */
   off_t byte_number = 1;	/* Byte number (1...) of difference. */
-  uintmax_t remaining = bytes;	/* Remaining number of bytes to compare.  */
+  intmax_t remaining = bytes;	/* Remaining bytes to compare, or -1.  */
   size_t read0, read1;		/* Number of bytes read from each file. */
   size_t first_diff;		/* Offset (0...) in buffers of 1st diff. */
   size_t smaller;		/* The lesser of 'read0' and 'read1'. */
@@ -433,7 +434,7 @@ cmp (void)
     {
       size_t bytes_to_read = buf_size;
 
-      if (remaining != UINTMAX_MAX)
+      if (0 <= remaining)
         {
           if (remaining < bytes_to_read)
             bytes_to_read = remaining;
diff --git a/src/diff.c b/src/diff.c
index e9c2b11..c545642 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -282,7 +282,7 @@ main (int argc, char **argv)
   bool show_c_function = false;
   char const *from_file = NULL;
   char const *to_file = NULL;
-  uintmax_t numval;
+  intmax_t numval;
   char *numend;
 
   /* Do our initializations.  */
@@ -350,8 +350,8 @@ main (int argc, char **argv)
           {
             if (optarg)
               {
-                numval = strtoumax (optarg, &numend, 10);
-                if (*numend)
+                numval = strtoimax (optarg, &numend, 10);
+                if (*numend || numval < 0)
                   try_help ("invalid context length '%s'", optarg);
                 if (CONTEXT_MAX < numval)
                   numval = CONTEXT_MAX;
@@ -525,7 +525,7 @@ main (int argc, char **argv)
           break;
 
         case 'W':
-          numval = strtoumax (optarg, &numend, 10);
+          numval = strtoimax (optarg, &numend, 10);
           if (! (0 < numval && numval <= SIZE_MAX) || *numend)
             try_help ("invalid width '%s'", optarg);
           if (width != numval)
@@ -554,8 +554,8 @@ main (int argc, char **argv)
           return EXIT_SUCCESS;
 
         case HORIZON_LINES_OPTION:
-          numval = strtoumax (optarg, &numend, 10);
-          if (*numend)
+          numval = strtoimax (optarg, &numend, 10);
+          if (*numend || numval < 0)
             try_help ("invalid horizon length '%s'", optarg);
           horizon_lines = MAX (horizon_lines, MIN (numval, LIN_MAX));
           break;
@@ -609,7 +609,7 @@ main (int argc, char **argv)
           break;
 
         case TABSIZE_OPTION:
-          numval = strtoumax (optarg, &numend, 10);
+          numval = strtoimax (optarg, &numend, 10);
           if (! (0 < numval && numval <= SIZE_MAX - GUTTER_WIDTH_MINIMUM)
               || *numend)
             try_help ("invalid tabsize '%s'", optarg);
diff --git a/src/ifdef.c b/src/ifdef.c
index 65f1745..43f1f86 100644
--- a/src/ifdef.c
+++ b/src/ifdef.c
@@ -135,7 +135,7 @@ format_group (register FILE *out, char const *format, char endchar,
             /* Print if-then-else format e.g. '%(n=1?thenpart:elsepart)'.  */
             {
               int i;
-              uintmax_t value[2];
+              intmax_t value[2];
               FILE *thenout, *elseout;
 
               for (i = 0; i < 2; i++)
@@ -144,7 +144,7 @@ format_group (register FILE *out, char const *format, char endchar,
                     {
                       char *fend;
                       errno = 0;
-                      value[i] = strtoumax (f, &fend, 10);
+                      value[i] = strtoimax (f, &fend, 10);
                       if (errno)
                         goto bad_format;
                       f = fend;
@@ -152,7 +152,7 @@ format_group (register FILE *out, char const *format, char endchar,
                   else
                     {
                       value[i] = groups_letter_value (groups, *f);
-                      if (value[i] == -1)
+                      if (value[i] < 0)
                         goto bad_format;
                       f++;
                     }
diff --git a/src/sdiff.c b/src/sdiff.c
index 2ef83da..a61f4e7 100644
--- a/src/sdiff.c
+++ b/src/sdiff.c
@@ -1098,15 +1098,15 @@ interact (struct line_filter *diff,
       else
         {
           char *numend;
-          uintmax_t val;
+          intmax_t val;
           lin llen, rlen, lenmax;
           errno = 0;
-          val = strtoumax (diff_help + 1, &numend, 10);
-          if (LIN_MAX < val || errno || *numend != ',')
+          val = strtoimax (diff_help + 1, &numend, 10);
+          if (! (0 <= val && val <= LIN_MAX) || errno || *numend != ',')
             fatal (diff_help);
           llen = val;
-          val = strtoumax (numend + 1, &numend, 10);
-          if (LIN_MAX < val || errno || *numend)
+          val = strtoimax (numend + 1, &numend, 10);
+          if (! (0 <= val && val <= LIN_MAX) || errno || *numend)
             fatal (diff_help);
           rlen = val;
 
-- 
2.17.1


--------------FB16B5F0F5D1BCC95D18486C--




From MAILER-DAEMON Tue Aug 27 20:57:05 2019
Received: from list by lists.gnu.org with archive (Exim 4.90_1)
	id 1i2mGn-0007LI-MN
	for mharc-bug-diffutils@gnu.org; Tue, 27 Aug 2019 20:57:05 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:60020)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2mGl-0007Ki-16
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 20:57:04 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2mGk-0005CJ-0A
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 20:57:02 -0400
Received: from debbugs.gnu.org ([209.51.188.43]:40818)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1i2mGj-0005CC-Se
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 20:57:01 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1i2mGj-0007Bz-R1
 for bug-diffutils@gnu.org; Tue, 27 Aug 2019 20:57:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Assaf Gordon <assafgordon@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 28 Aug 2019 00:57:01 +0000
Resent-Message-ID: <handler.35256.B35256.156695381927638@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 35256
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 35256@debbugs.gnu.org, alec@unifiedmathematics.com
Received: via spool by 35256-submit@debbugs.gnu.org id=B35256.156695381927638
 (code B ref 35256); Wed, 28 Aug 2019 00:57:01 +0000
Received: (at 35256) by debbugs.gnu.org; 28 Aug 2019 00:56:59 +0000
Received: from localhost ([127.0.0.1]:49639 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1i2mGh-0007Bh-Aq
 for submit@debbugs.gnu.org; Tue, 27 Aug 2019 20:56:59 -0400
Received: from mail-pl1-f193.google.com ([209.85.214.193]:43972)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <assafgordon@gmail.com>) id 1i2mGd-0007BQ-Cf
 for 35256@debbugs.gnu.org; Tue, 27 Aug 2019 20:56:57 -0400
Received: by mail-pl1-f193.google.com with SMTP id 4so360851pld.10
 for <35256@debbugs.gnu.org>; Tue, 27 Aug 2019 17:56:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; 
 h=subject:to:references:from:cc:message-id:date:user-agent
 :mime-version:in-reply-to:content-language:content-transfer-encoding;
 bh=EqJbYVLTHH0Id7xDpIRkEWcMj8tAnfxj1juEgIFVWWI=;
 b=F0ZzMgMSCrz/U/SDlY/kIXB/TPSv36XFj9gbbPUS5GC8iP6bBeSRHmA1IbhxtLGexx
 oY2L2xoUEzbLp+xiX1dRHTiNeB+wV/edxeKNvAjUmzw5wUIX/6MiQYWIYcOMusqjpf2x
 Z/oCmXYrJ686Y4FdFASFU9h0pU7jr/ULDZQn+CySz36Lwec4xuvUiiTTyjjE9IlryLQ4
 JhMalyIjYjZawnZ2w5qZNxMwjlosT9gSW8wHG38ftIDxCyM9VbX4i0SVUUMSoM2ZyyDX
 8yzn4YSfj0+UURD/4JpBuEfzp+NscBJVrcswxCzSeyzp6rT6FmJQlwhixr2n6Z2pGZR1
 vyEQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:subject:to:references:from:cc:message-id:date
 :user-agent:mime-version:in-reply-to:content-language
 :content-transfer-encoding;
 bh=EqJbYVLTHH0Id7xDpIRkEWcMj8tAnfxj1juEgIFVWWI=;
 b=GmUdokwDsglEd5E3E0jL7DXLfa/WXuchs2RzZMoE0zQQyUYqarXYuJKVwUwzMmRZnP
 L1DsTmghZqreAlH2B0ZRjMXilvEgW1Kfp9yuswFJQ6ES9OAYbrY/mwWhgxhUAz5Ln5Fl
 d3KtaMy4bprnVmpQ+IfE86KtNoogS6qD8xf5IZiC4EAKflJ7kej5BblWv4/jyTW8yEF0
 AJMVZkZW4npAZkqjjDb6TeYTMHMcBvF9VkDv1tFSpO9+vRKqk+NZ6DzWtbhzBGrqaDel
 YFHWYM3j458j4ndF7itdxkZ1BToWBCAeGt3ZD5YsZYilVaIQsF7FWLN2R5XDFGstU8uW
 xsUg==
X-Gm-Message-State: APjAAAVc0JxinoaflHd7lTyONq3ZtovdhTiJdG9oj6ZRE1aPZ/8zgU4g
 XWiPzVqW4qx3RBf5HZYxMyo=
X-Google-Smtp-Source: APXvYqxBn8Rw1GQPLI5BNWLWyoprwicKX4zQoZlioke6FeIz1dElVcF91HAIAHFi+fkt1ukXySxl4A==
X-Received: by 2002:a17:902:8696:: with SMTP id
 g22mr1757442plo.122.1566953809484; 
 Tue, 27 Aug 2019 17:56:49 -0700 (PDT)
Received: from tomato.moose.housegordon.com (moose.housegordon.com.
 [184.68.105.38])
 by smtp.googlemail.com with ESMTPSA id ev3sm6625095pjb.3.2019.08.27.17.56.47
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Tue, 27 Aug 2019 17:56:48 -0700 (PDT)
References: <8bbb0482c31d85f7bc37b78824e27c31d51ad479@webmail.unifiedmathematics.com>
 <14605a16-f1fb-fa44-7314-2092cf44ba75@cs.ucla.edu>
From: Assaf Gordon <assafgordon@gmail.com>
Message-ID: <73d7c2bc-bc70-764c-886d-272abc04bf4a@gmail.com>
Date: Tue, 27 Aug 2019 18:56:46 -0600
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.8.0
MIME-Version: 1.0
In-Reply-To: <14605a16-f1fb-fa44-7314-2092cf44ba75@cs.ucla.edu>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 209.51.188.43
Subject: [bug-diffutils] bug#35256: bug#35256: Bug report for -W argument
 (maximum width) - minor and not dangerous
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
 <mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
 <mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 28 Aug 2019 00:57:04 -0000

Hello,

Slightly off-topic, but potentially helpful:

On 2019-08-27 5:23 p.m., Paul Eggert wrote:
> alec@unifiedmathematics.com wrote:
> 
>> I know diff is used by A LOT of other programs, some of which are
>> web-accessible
> 
> [...] if you let a remote attacker 
> specify an arbitrary option to GNU diff there is lots of other trouble 
> you can get into. 
> [....] The general wisdom nowadays is to not expose command-line 
> operands to attackers.
While generally true, sometimes there's no way around it
(or perhaps it is even the goal).

An easy way to restrict resources is to execute a simple
wrapper shell script that uses 'timeout', 'prlimit' and 'setpriv' for
additional restrictions.

For example:

  timeout 10s \
    setpriv --no-new-privs \
      prlimit --cpu=3 --data=50000000 --nproc=1 \
        diff [ARGS]

will limit the "diff" process to running 10 seconds (of wall time),
consume up to 3 seconds of CPU time,
use up to 50MB of memory,
and limit to a single process (so it can't execute child processes).
The "setpriv" ensures it can't gain new privileges.

"prlimit" has more options (e.g. "--fsize" to limit file sizes
so it won't fill the drive, and "--nofiles" to limit number of open files).

These should work on any modern gnu/linux system
("timeout" is from coreutils, "setpriv" and "prlimit" are from util-linux).

None of the above is perfect,
but they add a quick layer of additional restrictions
(and they don't require additional privileges to use).

To take it a step further, you can use containers and tools such as
"bubblewrap" and "firefail" to isolate a process from the network,
from the filesystem, and even from other processes.


Hope this helps,
  -assaf




