[BusyBox] patch: awk segfaults on export of empty env vars
Keith Smith
keith at pharos.co.nz
Mon Nov 22 00:50:52 UTC 2004
Hi
Using 1.00-pre2, I have found that awk segfaults when empty environment variables are exported.
# export x=''
# awk
SIGSEGV
This was independently discovered elsewhere, and resulted in the following change to awk in CVS:
http://www.busybox.net/cgi-bin/cvsweb/busybox/editors/awk.c?r1=1.9&r2=1.10
However, I believe that the core problem lies with ash. It maintains the environment as an array of strings of the form 'name=value', but this format is not respected by setvar() as invoked by the export builtin. To demonstrate, note the different results for x and y:
~ # env
USER=root
HOME=/
LOGNAME=root
TERM=vt102
PATH=/usr/sbin:/bin:/usr/bin:/sbin
SHELL=/bin/sh
PWD=/
# y=''
# export y
# env
USER=root
HOME=/
LOGNAME=root
TERM=vt102
PATH=/usr/sbin:/bin:/usr/bin:/sbin
SHELL=/bin/sh
y=
PWD=/
# export x=''
# env
USER=root
HOME=/
x
LOGNAME=root
TERM=vt102
PATH=/usr/sbin:/bin:/usr/bin:/sbin
SHELL=/bin/sh
y=
PWD=/
So while awk _should_ be checking its inputs, it's not unreasonable to expect that _all_ entries in the environment will conform to the 'name=value' convention. I propose the following patch, which works fine in my testing, to resolve the issue.
Index: busybox-1.00-pre2/shell/ash.c
===================================================================
--- busybox-1.00-pre2/shell/ash.c (revision 1189)
+++ busybox-1.00-pre2/shell/ash.c (working copy)
@@ -11843,9 +11843,8 @@
}
INTOFF;
p = mempcpy(nameeq = ckmalloc(namelen + vallen + 2), name, namelen);
- *p++ = '\0';
+ *p++ = '=';
if (vallen) {
- p[-1] = '=';
p = mempcpy(p, val, vallen);
}
*p = '\0';
Can anybody think of a reason why this would be a bad idea?
Regards
Keith Smith
More information about the busybox
mailing list