NetBSD-Bugs archive

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

PR/60099 CVS commit: src/bin/sh



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

From: "Robert Elz" <kre%netbsd.org@localhost>
To: gnats-bugs%gnats.NetBSD.org@localhost
Cc: 
Subject: PR/60099 CVS commit: src/bin/sh
Date: Sun, 22 Mar 2026 20:27:52 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Sun Mar 22 20:27:52 UTC 2026
 
 Modified Files:
 	src/bin/sh: expand.c expand.h
 
 Log Message:
 PR bin/60099 - Fix unquoted $* ($@) expansion
 
 Make unquoted $* (or $@) when used in a context where field
 splitting happens (which requires unquoted of course) generate
 the same result, always, as would have been obtained had the
 number of params been known, and
 	$1 $2 $3 ... ${n}		(n is the value of $#)
 been used instead of $* - so for x$*y, for any strings x & y
 (including empty), the equivalent would be
 	x$1 $2 $3 ... ${n}y
 
 This must hold, whatever the setting of IFS (which affects
 how the fields generated are field split after they appear,
 but should not affect the generation of those fields).
 
 The bug this fixes is (in practice) never encountered, which is
 how it has persisted for so long, and in so many different shells.
 The method that was previously used to expand $* in this situation
 would work perfectly, if the first character of ${IFS} was an IFS
 whitespace character (which it usually is) - but could (sometimes)
 generate different results when IFS[0] was not a whitespace character.
 
 This fixes that, by expanding (this usage of) $* using code more
 similar to that used to handle "$@" (not quite identical, as
 "$@" must preserve empty fields, whereas $* should generally
 drop them.)
 
 While here, clean up the DEBUG code (used a lot while fixing
 this issue) and add a helper routine (only defined in DEBUG mode)
 to produce the visible form of a string, for tracing messages,
 to deal with non-ascii chars, incl \0, appearing in the string,
 which they can do a lot in these routines.   These changes are
 invisible (not included at all) in normal builds.
 
 Also while here, remove some long dead code (commented out, or
 #if 0) left around just in case earlier changes needed to be
 reverted - after many years, it is safe to say, that is not going
 to be happening now.   These changes just make the source file
 smaller, no other impact.
 
 Some 80 column, and similar, cleanups as well.
 
 NOTE:  This change will cause 2 of the current shell ATF tests
 to fail.   Those will be corrected in due course.   They were
 (inadvertantly) relying upon the broken behaviour of $*
 
 No pullups (not even to -11) planned, nothing really cares.
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.147 -r1.148 src/bin/sh/expand.c
 cvs rdiff -u -r1.26 -r1.27 src/bin/sh/expand.h
 
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
 



Home | Main Index | Thread Index | Old Index