blob: f2c949ef6b53694d91ccaec04fe899dc3988573e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
From b123f2395266a44176e49cee251fb776e97f26e1 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Sat, 24 Feb 2018 10:26:26 -0500
Subject: [PATCH] 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.
---
src/misc/getopt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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);
--
2.16.2
|