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
This commit is contained in:
parent
6764f54349
commit
f9ec075e88
@ -383,7 +383,7 @@ shiftcmd(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
ap2 = shellparam.p;
|
ap2 = shellparam.p;
|
||||||
while ((*ap2++ = *ap1++) != NULL);
|
while ((*ap2++ = *ap1++) != NULL);
|
||||||
shellparam.optnext = NULL;
|
shellparam.reset = 1;
|
||||||
INTON;
|
INTON;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -405,6 +405,7 @@ setcmd(int argc, char **argv)
|
|||||||
if (*argptr != NULL) {
|
if (*argptr != NULL) {
|
||||||
setparam(argptr);
|
setparam(argptr);
|
||||||
}
|
}
|
||||||
|
shellparam.reset = 1;
|
||||||
INTON;
|
INTON;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -414,7 +415,6 @@ void
|
|||||||
getoptsreset(const char *value)
|
getoptsreset(const char *value)
|
||||||
{
|
{
|
||||||
if (number(value) == 1) {
|
if (number(value) == 1) {
|
||||||
shellparam.optnext = NULL;
|
|
||||||
shellparam.reset = 1;
|
shellparam.reset = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user