From: Rich Felker Date: Sat, 24 Feb 2018 15:26:26 +0000 (-0500) Subject: fix getopt wrongly treating colons in optstring as valid option chars X-Git-Tag: v1.1.20~153 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b123f2395266a44176e49cee251fb776e97f26e1;p=oweals%2Fmusl.git fix getopt wrongly treating colons in optstring as valid option chars the ':' in optstring has special meaning as a flag applying to the previous option character, or to getopt's error handling behavior when it appears at the beginning. don't also accept a "-:" option based on its presence. --- diff --git a/src/misc/getopt.c b/src/misc/getopt.c index e9bab41c..e921a60e 100644 --- a/src/misc/getopt.c +++ b/src/misc/getopt.c @@ -77,7 +77,7 @@ int getopt(int argc, char * const argv[], const char *optstring) if (l>0) i+=l; else i++; } while (l && d != c); - if (d != c) { + if (d != c || c == ':') { optopt = c; if (optstring[0] != ':' && opterr) __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);