mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
getopt: fix null pointer arithmetic ub
When an option that requires an argument is the last character of argv[argc-1], getopt computes argv[argc] + optpos. While optpos is always zero in this case, adding it to null pointer is still undefined.
This commit is contained in:
parent
35e9831156
commit
6d322159c6
1 changed files with 2 additions and 1 deletions
|
@ -87,7 +87,8 @@ int getopt(int argc, char * const argv[], const char *optstring)
|
|||
if (optstring[i] == ':') {
|
||||
optarg = 0;
|
||||
if (optstring[i+1] != ':' || optpos) {
|
||||
optarg = argv[optind++] + optpos;
|
||||
optarg = argv[optind++];
|
||||
if (optpos) optarg += optpos;
|
||||
optpos = 0;
|
||||
}
|
||||
if (optind > argc) {
|
||||
|
|
Loading…
Add table
Reference in a new issue