summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorstefanf <stefanf@FreeBSD.org>2008-03-22 14:06:01 +0000
committerstefanf <stefanf@FreeBSD.org>2008-03-22 14:06:01 +0000
commitd52b1cf43ee9e8d06f32d2bd3eb47d345b42e0ff (patch)
tree852cb926560b98ec887858eb301752feb0b6b02a /bin/sh
parent89b08d11a7a3b73300a21c74f2bfb12da246303c (diff)
downloadFreeBSD-src-d52b1cf43ee9e8d06f32d2bd3eb47d345b42e0ff.zip
FreeBSD-src-d52b1cf43ee9e8d06f32d2bd3eb47d345b42e0ff.tar.gz
Reset the internal state used for the 'getopts' built-in when 'shift' or 'set'
are used to modify the arguments. Not doing so caused random memory reads or null pointer dereferences when 'getopts' was called again later (SUSv3 says getopts produces unspecified results in this case). PR: 48318
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/options.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/bin/sh/options.c b/bin/sh/options.c
index 58c5c7b..ff5736d 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -383,7 +383,7 @@ shiftcmd(int argc, char **argv)
}
ap2 = shellparam.p;
while ((*ap2++ = *ap1++) != NULL);
- shellparam.optnext = NULL;
+ shellparam.reset = 1;
INTON;
return 0;
}
@@ -405,6 +405,7 @@ setcmd(int argc, char **argv)
if (*argptr != NULL) {
setparam(argptr);
}
+ shellparam.reset = 1;
INTON;
return 0;
}
@@ -414,7 +415,6 @@ void
getoptsreset(const char *value)
{
if (number(value) == 1) {
- shellparam.optnext = NULL;
shellparam.reset = 1;
}
}
OpenPOWER on IntegriCloud