summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--src/cut.c2
-rwxr-xr-xtests/misc/cut4
3 files changed, 12 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 9c5a5a841..a367d8d71 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ cut could segfault when invoked with a user-specified output
+ delimiter and an unbounded range like "-f1234567890-".
+ [bug introduced in coreutils-5.3.0]
+
* Noteworthy changes in release 8.10 (2011-02-04) [stable]
diff --git a/src/cut.c b/src/cut.c
index 3f8e3e631..e2fe85170 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -496,6 +496,8 @@ set_fields (const char *fieldstr)
if (rp[i].hi > max_range_endpoint)
max_range_endpoint = rp[i].hi;
}
+ if (max_range_endpoint < eol_range_start)
+ max_range_endpoint = eol_range_start;
/* Allocate an array large enough so that it may be indexed by
the field numbers corresponding to all finite ranges
diff --git a/tests/misc/cut b/tests/misc/cut
index 435399463..c905ba9a3 100755
--- a/tests/misc/cut
+++ b/tests/misc/cut
@@ -150,6 +150,10 @@ my @Tests =
{ERR=>$no_endpoint}],
['inval5', '-f', '1-,-', {IN=>''}, {OUT=>''}, {EXIT=>1}, {ERR=>$no_endpoint}],
['inval6', '-f', '-1,-', {IN=>''}, {OUT=>''}, {EXIT=>1}, {ERR=>$no_endpoint}],
+ # This would evoke a segfault from 5.3.0..6.10
+ ['big-unbounded-b', '--output-d=:', '-b1234567890-', {IN=>''}, {OUT=>''}],
+ ['big-unbounded-c', '--output-d=:', '-c1234567890-', {IN=>''}, {OUT=>''}],
+ ['big-unbounded-f', '--output-d=:', '-f1234567890-', {IN=>''}, {OUT=>''}],
);
@Tests = triple_test \@Tests;