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: Michael Cheponis <michael.cheponis%gmail.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost, mac%culver.net@localhost
Subject: Re: bin/59903: rs dumps core on valid input
Date: Sat, 10 Jan 2026 19:14:18 -0800

 --00000000000092aac4064814295b
 Content-Type: text/plain; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable
 
 This patch works for me (I had some additional test cases I didn't put in
 the pr; they pass now).
 
 To my eyes:
 
 1) Gosh, there are precious few comments in there
 
 2) Definitely some questionable code style choices for 2026 C
 
 Thanks for the quick turn-around.
 
 -Mike
 
 
 On Sat, Jan 10, 2026 at 1:45=E2=80=AFAM RVP via gnats <gnats-admin@netbsd.o=
 rg>
 wrote:
 
 > 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 =3D elem, i =3D 0; i < ocols; i++) {
 >  -                              for (j =3D 0; j < orows; j++)
 >  +                              for (j =3D 0; j < orows; j++) {
 >  +                                      if (ep >=3D elem + nelem)
 >  +                                              break;
 >                                         if ((n =3D strlen(*ep++)) > max)
 >                                                 max =3D n;
 >  +                              }
 >                                 colwidths[i] =3D max + gutter;
 >                         }
 >                 else
 >  ---END patch---
 >
 >  -RVP
 >
 >
 
 --00000000000092aac4064814295b
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable
 
 <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:arial,he=
 lvetica,sans-serif;font-size:small">This patch works for me (I had some add=
 itional test cases I didn&#39;t put in the pr; they pass now).</div><div cl=
 ass=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-=
 size:small"><br></div><div class=3D"gmail_default" style=3D"font-family:ari=
 al,helvetica,sans-serif;font-size:small">To my eyes:</div><div class=3D"gma=
 il_default" style=3D"font-family:arial,helvetica,sans-serif;font-size:small=
 "><br></div><div class=3D"gmail_default" style=3D"font-family:arial,helveti=
 ca,sans-serif;font-size:small">1) Gosh, there are precious few comments in =
 there</div><div class=3D"gmail_default" style=3D"font-family:arial,helvetic=
 a,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" style=
 =3D"font-family:arial,helvetica,sans-serif;font-size:small">2) Definitely s=
 ome questionable code style choices for 2026 C</div><div class=3D"gmail_def=
 ault" style=3D"font-family:arial,helvetica,sans-serif;font-size:small"><br>=
 </div><div class=3D"gmail_default" style=3D"font-family:arial,helvetica,san=
 s-serif;font-size:small">Thanks for the quick turn-around.</div><div class=
 =3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif;font-siz=
 e:small"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,=
 helvetica,sans-serif;font-size:small">-Mike</div><div class=3D"gmail_defaul=
 t" style=3D"font-family:arial,helvetica,sans-serif;font-size:small"><br></d=
 iv></div><br><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"l=
 tr" class=3D"gmail_attr">On Sat, Jan 10, 2026 at 1:45=E2=80=AFAM RVP via gn=
 ats &lt;<a href=3D"mailto:gnats-admin%netbsd.org@localhost";>gnats-admin%netbsd.org@localhost</a=
 >&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px=
  0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The=
  following reply was made to PR bin/59903; it has been noted by GNATS.<br>
 <br>
 From: RVP &lt;<a href=3D"mailto:rvp%SDF.ORG@localhost"; target=3D"_blank">rvp%SDF.ORG@localhost<=
 /a>&gt;<br>
 To: <a href=3D"mailto:gnats-bugs%netbsd.org@localhost"; target=3D"_blank">gnats-bugs@n=
 etbsd.org</a><br>
 Cc: <br>
 Subject: Re: bin/59903: rs dumps core on valid input<br>
 Date: Sat, 10 Jan 2026 07:18:36 +0000 (UTC)<br>
 <br>
 =C2=A0On Sat, 10 Jan 2026, <a href=3D"mailto:mac%culver.net@localhost"; target=3D"_bla=
 nk">mac%culver.net@localhost</a> via gnats wrote:<br>
 <br>
 =C2=A0&gt; $ cat 2x10<br>
 =C2=A0&gt; 43=C2=A0 =C2=A027=C2=A0 =C2=A08=C2=A0 =C2=A0 22=C2=A0 =C2=A012=
 =C2=A0 =C2=A078=C2=A0 =C2=A018=C2=A0 =C2=A043=C2=A0 =C2=A041=C2=A0 =C2=A013=
 <br>
 =C2=A0&gt; 76=C2=A0 =C2=A029=C2=A0 =C2=A085=C2=A0 =C2=A0100=C2=A0 34=C2=A0 =
 =C2=A078=C2=A0 =C2=A045=C2=A0 =C2=A080=C2=A0 =C2=A024=C2=A0 =C2=A050<br>
 =C2=A0&gt;<br>
 =C2=A0&gt; $ rs -tz &lt; 2x10<br>
 =C2=A0&gt; zsh: segmentation fault=C2=A0 rs -tz &lt; 2x10<br>
 =C2=A0&gt; [...]<br>
 =C2=A0&gt; test files generated by playing around with this:<br>
 =C2=A0&gt;<br>
 =C2=A0&gt; $ cd /tmp<br>
 =C2=A0&gt; $ jot -r 100 | rs 10 10 | tee 10x10 | rs -T &gt; T10x10<br>
 =C2=A0&gt; [...]<br>
 =C2=A0&gt;<br>
 <br>
 =C2=A0These also fail:<br>
 <br>
 =C2=A0```<br>
 =C2=A0$ jot 100 | rs -tz=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# c=
 alculated orows * ocols &gt; nelem<br>
 =C2=A0$ jot 99 | rs -tz 10 10=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
 =A0 =C2=A0 # dim &gt; nelem<br>
 =C2=A0```<br>
 <br>
 =C2=A0Looks like it&#39;s walking off the end of the `elem&#39; array. Can =
 you try:<br>
 <br>
 =C2=A0---START patch---<br>
 =C2=A0diff -urN a/src/usr.bin/rs/rs.c b/src/usr.bin/rs/rs.c<br>
 =C2=A0--- a/src/usr.bin/rs/rs.c=C2=A0 =C2=A0 =C2=A0 2023-08-10 20:36:29.000=
 000000 +0000<br>
 =C2=A0+++ b/src/usr.bin/rs/rs.c=C2=A0 =C2=A0 =C2=A0 2026-01-10 06:28:57.921=
 214613 +0000<br>
 =C2=A0@@ -295,9 +295,12 @@<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (flags &amp; SQUEEZE) {<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (flags &amp; TRA=
 NSPOSE)<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C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
 =C2=A0 =C2=A0 =C2=A0 max =3D n;<br>
 =C2=A0+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
 =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
 =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 colwidths[i] =3D max + gutter;<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
 =A0 =C2=A0 }<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else<br>
 =C2=A0---END patch---<br>
 <br>
 =C2=A0-RVP<br>
 <br>
 </blockquote></div>
 
 --00000000000092aac4064814295b--
 


Home | Main Index | Thread Index | Old Index