Subject: bin/28852: sh variable assignement bug
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Martin Husemann <martin@duskware.de>
List: netbsd-bugs
Date: 01/03/2005 21:30:00
>Number:         28852
>Category:       bin
>Synopsis:       sh variable assignement bug
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 03 21:30:00 +0000 2005
>Originator:     Martin Husemann
>Release:        NetBSD 2.99.12
>Organization:
>Environment:
System: NetBSD sunny-weather.duskware.de 2.99.12 NetBSD 2.99.12 (SUNNY) #2: Mon Jan 3 12:55:16 CET 2005 martin@sunny-weather.duskware.de:/usr/src/sys/arch/sparc64/compile/SUNNY sparc64
Architecture: sparc64
Machine: sparc64
>Description:

In some cases building a kernel (natively) on sparc64 fails because
"newvers.sh" generates broken C code in vers.c. This bug is not new, it
has been triggered by addition of 2005 to the copyright message.

>How-To-Repeat:
This looks like a memory management bug in /bin/sh. It is highly volatile:
copying "copyright" and "newvers.sh" to /tmp and running it there fixes the
bug. Removing the "5" from "2005" in "copyright" avoids it too.

Of course (heh!) everything works fine on 32bit archs.

Here is a sh -x transscript showing the bug (note the missing " after
the second "All rights reserved.")

[/usr/src/sys/arch/sparc64/compile/SUNNY] martin@sunny-weather >  sh -x ../../../../conf/newvers.sh
+ [ ! -e version ]
+ cat version
+ v=9
+ date
+ t=Mon Jan  3 22:12:49 CET 2005
+ u=martin
+ hostname
+ h=sunny-weather.duskware.de
+ pwd
+ d=/usr/src/sys/arch/sparc64/compile/SUNNY
+ dirname ../../../../conf/newvers.sh
+ cwd=../../../../conf
+ awk { print "\""$0"\\n\""} ../../../../conf/copyright
+ copyright="Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005\n"
"    The NetBSD Foundation, Inc.  All rights reserved.\n"
"Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
"    The Regents of the University of California.  All rights reserved.\n
+ [ -f ident ]
+ basename /usr/src/sys/arch/sparc64/compile/SUNNY
+ id=SUNNY
+ osrelcmd=../../../../conf/osrelease.sh
+ ost=NetBSD
+ sh ../../../../conf/osrelease.sh
+ osr=2.99.12
+ fullversion=NetBSD 2.99.12 (SUNNY) #9: Mon Jan  3 22:12:49 CET 2005\n\tmartin@sunny-weather.duskware.de:/usr/src/sys/arch/sparc64/compile/SUNNY\n
+ cat
+ expr 9 + 1
+ echo 10

The awk output itself is ok:

[/usr/src/sys/arch/sparc64/compile/SUNNY] martin@sunny-weather > awk '{ print "\""$0"\\n\""}' ../../../../conf/copyright
"Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005\n"
"    The NetBSD Foundation, Inc.  All rights reserved.\n"
"Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
"    The Regents of the University of California.  All rights reserved.\n"


>Fix:
n/a