NetBSD-Bugs archive

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

bin/58421: awk(1) goes into infinite loop when reading dirs. on tmpfs



>Number:         58421
>Category:       bin
>Synopsis:       awk(1) goes into infinite loop when reading dirs. on tmpfs
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 11 23:15:00 +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---



Home | Main Index | Thread Index | Old Index