tech-pkg archive

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

bugfix: lang/nawk: prevent segfault on NetBSD



In my pkgsrc installation on NetBSD 10.99.x, I ran bootstrap with the
--full option and thus ended up with lang/nawk being used. I don't
remember what I originally did to crash nawk, but minimal reproducers are:

env -i X=ä nawk -f /dev/null		# lib.c:796
env -i X=0ä nawk -f /dev/null		# lib.c:800
env -i X=x1ä nawk -f /dev/null	# fine (neither 0x nor nan nor inf)
env -i X=+nanä nawk -f /dev/null	# lib.c:808
env -i X=+ä nawk -f /dev/null		# lib.c:810
env -i X=/ä nawk -f /dev/null		# fine
env -i X=123ä nawk -f /dev/null		# lib.c:831

The call in lib.c:813 is not triggerable, as it would already trigger in
line 796.

Only the code in is_valid_number is affected; the other places either
come from input(), which returns an unsigned char, or they cast to
uschar already.

Fine to commit?
? lang/nawk/files/FIXES.ctype
Index: lang/nawk/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/lang/nawk/Makefile,v
retrieving revision 1.47
diff -u -r1.47 Makefile
--- lang/nawk/Makefile	19 Apr 2025 08:07:27 -0000	1.47
+++ lang/nawk/Makefile	9 Jul 2025 18:17:00 -0000
@@ -1,6 +1,6 @@
 # $NetBSD: Makefile,v 1.47 2025/04/19 08:07:27 wiz Exp $
 
-DISTNAME=	nawk-20230909
+DISTNAME=	nawk-20250709
 CATEGORIES=	lang
 MASTER_SITES=	# empty
 DISTFILES=	# empty
Index: lang/nawk/files/FIXES
===================================================================
RCS file: /cvsroot/pkgsrc/lang/nawk/files/FIXES,v
retrieving revision 1.6
diff -u -r1.6 FIXES
--- lang/nawk/files/FIXES	9 Jul 2025 17:11:22 -0000	1.6
+++ lang/nawk/files/FIXES	9 Jul 2025 18:17:00 -0000
@@ -25,6 +25,10 @@
 This file lists all bug fixes, changes, etc., made since the AWK book
 was sent to the printers in August 1987.
 
+Jul 09, 2025:
+	Fix segmentation fault on NetBSD 10.99 due to invalid usage of the
+	character classification functions in <ctype.h>.
+
 Sep 06, 2023:
 	Fix edge case where FS is changed on commandline. Thanks to
 	Gordon Shephard and Miguel Pineiro Jr.
Index: lang/nawk/files/lib.c
===================================================================
RCS file: /cvsroot/pkgsrc/lang/nawk/files/lib.c,v
retrieving revision 1.7
diff -u -r1.7 lib.c
--- lang/nawk/files/lib.c	17 Sep 2023 10:32:06 -0000	1.7
+++ lang/nawk/files/lib.c	9 Jul 2025 18:17:00 -0000
@@ -793,11 +793,11 @@
 	if (no_trailing)
 		*no_trailing = false;
 
-	while (isspace(*s))
+	while (isspace((uschar) *s))
 		s++;
 
 	// no hex floating point, sorry
-	if (s[0] == '0' && tolower(s[1]) == 'x')
+	if (s[0] == '0' && tolower((uschar) s[1]) == 'x')
 		return false;
 
 	// allow +nan, -nan, +inf, -inf, any other letter, no
@@ -805,12 +805,12 @@
 		is_nan = (strncasecmp(s+1, "nan", 3) == 0);
 		is_inf = (strncasecmp(s+1, "inf", 3) == 0);
 		if ((is_nan || is_inf)
-		    && (isspace(s[4]) || s[4] == '\0'))
+		    && (isspace((uschar) s[4]) || s[4] == '\0'))
 			goto convert;
-		else if (! isdigit(s[1]) && s[1] != '.')
+		else if (! isdigit((uschar) s[1]) && s[1] != '.')
 			return false;
 	}
-	else if (! isdigit(s[0]) && s[0] != '.')
+	else if (! isdigit((uschar) s[0]) && s[0] != '.')
 		return false;
 
 convert:
@@ -828,7 +828,7 @@
 	/*
 	 * check for trailing stuff
 	 */
-	while (isspace(*ep))
+	while (isspace((uschar) *ep))
 		ep++;
 
 	if (no_trailing != NULL)


Home | Main Index | Thread Index | Old Index