diff options
author | Alexey Izbyshev <izbyshev@ispras.ru> | 2023-03-10 20:00:31 +0300 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2023-04-11 09:18:38 -0400 |
commit | 6d322159c633050a405b03b927db76b89e402014 (patch) | |
tree | 3c8fe56b45f18e2a80fcda63f854ee6fef3b2703 | |
parent | 35e9831156efc1b54e1a91917ba0f787d5df3353 (diff) | |
download | musl-6d322159c633050a405b03b927db76b89e402014.tar.gz musl-6d322159c633050a405b03b927db76b89e402014.tar.bz2 musl-6d322159c633050a405b03b927db76b89e402014.tar.xz musl-6d322159c633050a405b03b927db76b89e402014.zip |
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.
-rw-r--r-- | src/misc/getopt.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/misc/getopt.c b/src/misc/getopt.c index c3f66995..b02b81c3 100644 --- a/src/misc/getopt.c +++ b/src/misc/getopt.c @@ -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) { |