NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/59903: rs dumps core on valid input



The following reply was made to PR bin/59903; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/59903: rs dumps core on valid input
Date: Sat, 10 Jan 2026 07:18:36 +0000 (UTC)

 On Sat, 10 Jan 2026, mac%culver.net@localhost via gnats wrote:
 
 > $ cat 2x10
 > 43   27   8    22   12   78   18   43   41   13
 > 76   29   85   100  34   78   45   80   24   50
 >
 > $ rs -tz < 2x10
 > zsh: segmentation fault  rs -tz < 2x10
 > [...]
 > test files generated by playing around with this:
 >
 > $ cd /tmp
 > $ jot -r 100 | rs 10 10 | tee 10x10 | rs -T > T10x10
 > [...]
 >
 
 These also fail:
 
 ```
 $ jot 100 | rs -tz		# calculated orows * ocols > nelem
 $ jot 99 | rs -tz 10 10		# dim > nelem
 ```
 
 Looks like it's walking off the end of the `elem' array. Can you try:
 
 ---START patch---
 diff -urN a/src/usr.bin/rs/rs.c b/src/usr.bin/rs/rs.c
 --- a/src/usr.bin/rs/rs.c	2023-08-10 20:36:29.000000000 +0000
 +++ b/src/usr.bin/rs/rs.c	2026-01-10 06:28:57.921214613 +0000
 @@ -295,9 +295,12 @@
   	if (flags & SQUEEZE) {
   		if (flags & TRANSPOSE)
   			for (ep = elem, i = 0; i < ocols; i++) {
 -				for (j = 0; j < orows; j++)
 +				for (j = 0; j < orows; j++) {
 +					if (ep >= elem + nelem)
 +						break;
   					if ((n = strlen(*ep++)) > max)
   						max = n;
 +				}
   				colwidths[i] = max + gutter;
   			}
   		else
 ---END patch---
 
 -RVP
 


Home | Main Index | Thread Index | Old Index