projects
/
musl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
35e9831
)
getopt: fix null pointer arithmetic ub
author
Alexey Izbyshev
<izbyshev@ispras.ru>
Fri, 10 Mar 2023 17:00:31 +0000
(20:00 +0300)
committer
Rich Felker
<dalias@aerifal.cx>
Tue, 11 Apr 2023 13:18:38 +0000
(09:18 -0400)
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.
src/misc/getopt.c
patch
|
blob
|
history
diff --git
a/src/misc/getopt.c
b/src/misc/getopt.c
index
c3f6699
..
b02b81c
100644
(file)
--- 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) {