NetBSD Problem Report #58421

From www@netbsd.org  Thu Jul 11 23:10:20 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id AB3221A9238
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 11 Jul 2024 23:10:20 +0000 (UTC)
Message-Id: <20240711231018.DA4791A9239@mollari.NetBSD.org>
Date: Thu, 11 Jul 2024 23:10:18 +0000 (UTC)
From: rvp@SDF.ORG
Reply-To: rvp@SDF.ORG
To: gnats-bugs@NetBSD.org
Subject: awk(1) goes into infinite loop when reading dirs. on tmpfs
X-Send-Pr-Version: www-1.0

>Number:         58421
>Notify-List:    riastradh@NetBSD.org
>Category:       bin
>Synopsis:       awk(1) goes into infinite loop when reading dirs. on tmpfs
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    christos
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 11 23:15:00 +0000 2024
>Closed-Date:    
>Last-Modified:  Mon Oct 14 17:20:01 +0000 2024
>Originator:     RVP
>Release:        NetBSD/amd64 10.99.11
>Organization:
>Environment:
NetBSD CoreBook.local 10.99.11 NetBSD 10.99.11 (COREBOOK) #0: Thu Jul 10 23:29:51 UTC 2024  bld@CoreBook.local:/tmp/obj/usr/src/sys/arch/amd64/compile/COREBOOK amd64
>Description:
awk goes into an infinite loop when the input file is a directory
on a tmpfs filesystem.

On physical (ie. UFS) filesystems, getc() etc. succeeds and returns
dir. data, but, on reading a dir. on tmpfs, a read error occurs and
this isn't handled properly by awk-20200218.
>How-To-Repeat:
# mount -t tmpfs tmpfs /tmp
$ awk '{ print NF }' /tmp
...infinite loop...
<Ctrl-C>
$
>Fix:
Fudged from upstream version awk-20220122 (Note: far better, in my
opinion, to just update the in-tree awk to the latest upstream.):

---START patch---
diff -urN a/src/external/historical/nawk/dist/lib.c b/src/external/historical/nawk/dist/lib.c
--- a/src/external/historical/nawk/dist/lib.c	2020-08-31 23:37:55.000000000 +0000
+++ b/src/external/historical/nawk/dist/lib.c	2024-07-11 22:42:14.089857741 +0000
@@ -240,6 +240,7 @@
 		}
 		if (found)
 			setptr(patbeg, '\0');
+		isrec = (found == 0 && *buf == '\0') ? false : true;
 	} else {
 		if ((sep = *rs) == 0) {
 			sep = '\n';
@@ -269,10 +270,10 @@
 		if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3"))
 			FATAL("input record `%.30s...' too long", buf);
 		*rr = 0;
+		isrec = (c == EOF && rr == buf) ? false : true;
 	}
 	*pbuf = buf;
 	*pbufsize = bufsize;
-	isrec = *buf || !feof(inf);
 	   dprintf( ("readrec saw <%s>, returns %d\n", buf, isrec) );
 	return isrec;
 }
---END patch---

>Release-Note:

>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/58421: awk(1) goes into infinite loop when reading dirs. on tmpfs
Date: Fri, 12 Jul 2024 09:43:23 +0700

     Date:        Thu, 11 Jul 2024 23:15:00 +0000 (UTC)
     From:        rvp@SDF.ORG
     Message-ID:  <20240711231500.DB96F1A923A@mollari.NetBSD.org>

   | +		isrec = (found == 0 && *buf == '\0') ? false : true;

 Surely that's just:
 		isrec = !(found == 0 && *buf == '\0');
 or simplified:
 		isrec = found != 0 || *buf != '\0';
 or if you prefer brevity:
 		isrec = found || *buf;

 Why bother with the ? : operator in a case like that?


   | +		isrec = (c == EOF && rr == buf) ? false : true;

 And similarly there:
 		isrec = c != EOF || rr != buf;

 kre

From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: Robert Elz <kre@munnari.OZ.AU>
Subject: Re: bin/58421: awk(1) goes into infinite loop when reading dirs. on
 tmpfs
Date: Sun, 14 Jul 2024 22:20:53 +0000 (UTC)

 On Fri, 12 Jul 2024, Robert Elz wrote:

 >   | +		isrec = (found == 0 && *buf == '\0') ? false : true;
 >
 > Surely that's just:
 > 		isrec = !(found == 0 && *buf == '\0');
 > or simplified:
 > 		isrec = found != 0 || *buf != '\0';
 > or if you prefer brevity:
 > 		isrec = found || *buf;
 >
 > Why bother with the ? : operator in a case like that?
 >
 >
 >   | +		isrec = (c == EOF && rr == buf) ? false : true;
 >
 > And similarly there:
 > 		isrec = c != EOF || rr != buf;
 >

 :) All true, except, this should go upstream. Even the latest version is like
 that:

 https://github.com/onetrueawk/awk/blob/master/lib.c#L251

 (Just wanted to get someone to update awk with this PR, actually.)

 Cheers!

 -RVP

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58421 CVS commit: src/external/historical/nawk/dist
Date: Sun, 21 Jul 2024 15:48:47 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jul 21 19:48:47 UTC 2024

 Modified Files:
 	src/external/historical/nawk/dist: lib.c

 Log Message:
 PR/58421: RVP: fix readdir on tmpfs. Upstream merge is complicated now because
 the bsd branch has not been updated in ages.


 To generate a diff of this commit:
 cvs rdiff -u -r1.13 -r1.14 src/external/historical/nawk/dist/lib.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 23 Jul 2024 20:42:22 +0000
State-Changed-Why:
probably needs pullup-10 and pullup-9


From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: Christos Zoulas <christos@netbsd.org>
Subject: Re: PR/58421 CVS commit: src/external/historical/nawk/dist
Date: Sun, 28 Jul 2024 22:53:07 +0000 (UTC)

 On Sun, 21 Jul 2024, Christos Zoulas wrote:

 > Log Message:
 > PR/58421: RVP: fix readdir on tmpfs. Upstream merge is complicated now because
 > the bsd branch has not been updated in ages.
 >

 Do you mean the gensub, bitops and time-related additions in the bsd-features
 branch?

 https://github.com/onetrueawk/awk/compare/master...bsd-features

 Apart from the new mktime() from OpenBSD:

 https://github.com/onetrueawk/awk/pull/241

 that branch is now up-to-date with master.

 Thx,

 -RVP

From: Christos Zoulas <christos@zoulas.com>
To: gnats-bugs@netbsd.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, rvp@sdf.org
Subject: Re: PR/58421 CVS commit: src/external/historical/nawk/dist
Date: Mon, 29 Jul 2024 08:14:53 -0400

 Yes, I saw!

 christos

 > On Jul 28, 2024, at 6:55=E2=80=AFPM, RVP <rvp@sdf.org> wrote:
 >=20
 > =EF=BB=BFThe following reply was made to PR bin/58421; it has been noted b=
 y GNATS.
 >=20
 > From: RVP <rvp@SDF.ORG>
 > To: gnats-bugs@netbsd.org
 > Cc: Christos Zoulas <christos@netbsd.org>
 > Subject: Re: PR/58421 CVS commit: src/external/historical/nawk/dist
 > Date: Sun, 28 Jul 2024 22:53:07 +0000 (UTC)
 >=20
 >> On Sun, 21 Jul 2024, Christos Zoulas wrote:
 >>=20
 >> Log Message:
 >> PR/58421: RVP: fix readdir on tmpfs. Upstream merge is complicated now be=
 cause
 >> the bsd branch has not been updated in ages.
 >>=20
 >=20
 > Do you mean the gensub, bitops and time-related additions in the bsd-featu=
 res
 > branch?
 >=20
 > https://github.com/onetrueawk/awk/compare/master...bsd-features
 >=20
 > Apart from the new mktime() from OpenBSD:
 >=20
 > https://github.com/onetrueawk/awk/pull/241
 >=20
 > that branch is now up-to-date with master.
 >=20
 > Thx,
 >=20
 > -RVP
 >=20

Responsible-Changed-From-To: bin-bug-people->christos
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Sun, 13 Oct 2024 23:56:10 +0000
Responsible-Changed-Why:
Christos, can I trouble you to figure out the pullups needed?


From: Christos Zoulas <christos@zoulas.com>
To: gnats-bugs@netbsd.org
Cc: christos@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,
 riastradh@netbsd.org, rvp@sdf.org
Subject: Re: bin/58421 (awk(1) goes into infinite loop when reading dirs. on tmpfs)
Date: Mon, 14 Oct 2024 08:39:40 -0400

 Will look.

 christos

 > On Oct 13, 2024, at 7:56=E2=80=AFPM, riastradh@netbsd.org wrote:
 >=20
 > =EF=BB=BFSynopsis: awk(1) goes into infinite loop when reading dirs. on tm=
 pfs
 >=20
 > Responsible-Changed-From-To: bin-bug-people->christos
 > Responsible-Changed-By: riastradh@NetBSD.org
 > Responsible-Changed-When: Sun, 13 Oct 2024 23:56:10 +0000
 > Responsible-Changed-Why:
 > Christos, can I trouble you to figure out the pullups needed?
 >=20
 >=20

From: Christos Zoulas <christos@zoulas.com>
To: gnats-bugs@netbsd.org
Cc: christos@netbsd.org,
 gnats-admin@netbsd.org,
 netbsd-bugs@netbsd.org,
 "rvp@sdf.org" <rvp@SDF.ORG>,
 "riastradh@netbsd.org" <riastradh@NetBSD.org>
Subject: Re: bin/58421 (awk(1) goes into infinite loop when reading dirs. on
 tmpfs)
Date: Mon, 14 Oct 2024 13:18:24 -0400

 --Apple-Mail=_280EE327-B0EC-4AB5-9106-176880C67632
 Content-Transfer-Encoding: quoted-printable
 Content-Type: text/plain;
 	charset=us-ascii

 revision 1.14
 date: 2024-07-21 15:48:47 -0400;  author: christos;  state: Exp;  lines: =
 +2 -1;  commitid: RTCSFBtRdLT07KiF;
 PR/58421: RVP: fix readdir on tmpfs. Upstream merge is complicated now =
 because
 the bsd branch has not been updated in ages.



 --Apple-Mail=_280EE327-B0EC-4AB5-9106-176880C67632
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename=signature.asc
 Content-Type: application/pgp-signature;
 	name=signature.asc
 Content-Description: Message signed with OpenPGP

 -----BEGIN PGP SIGNATURE-----
 Comment: GPGTools - http://gpgtools.org

 iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCZw1SYAAKCRBxESqxbLM7
 OixLAKDHbaKWXHjLOzB15g7MMpq4v+sRcQCg21I0Mb+4U7MuzHiO620Lch/Wwp0=
 =Kjs9
 -----END PGP SIGNATURE-----

 --Apple-Mail=_280EE327-B0EC-4AB5-9106-176880C67632--

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.