diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2019-01-04 03:13:24 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2019-01-04 03:13:24 +0000 |
commit | 253b638eabd53fe4a1f26dbffbc7387180cbdaa0 (patch) | |
tree | 3b14f37e2dc33659a9f84c99d12c59280605a5e0 /lib | |
parent | 07372194c3016882494a28a8a1ae00472ce31e69 (diff) | |
download | src-253b638eabd53fe4a1f26dbffbc7387180cbdaa0.tar.gz src-253b638eabd53fe4a1f26dbffbc7387180cbdaa0.zip |
getopt_long(3): fix case of malformed long opt
When presented with an arg string like '-l-', getopt_long will successfully
parse out the 'l' short option, then proceed to match '--' against the first
longopts entry as it later does a strncmp with len=0. This latter bit is
arguably another bug in itself, but presumably not a practical issue as all
callers of parse_long_options are already doing the right thing (except this
one pointed out).
An opt string like '-l-' should be considered malformed and throw a bad
argument rather than behaving as if '--' were passed. It cannot possibly do
what the invoker expects, and it's probably the result of a typo (ls -l- a)
rather than any intent.
Reported by: Tony Overfield <toverfield@yahoo.com>
Reviewed by: imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D18616
Notes
Notes:
svn path=/head/; revision=342757
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdlib/getopt_long.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index 9534a2aff67e..4d92fd0cd45d 100644 --- a/lib/libc/stdlib/getopt_long.c +++ b/lib/libc/stdlib/getopt_long.c @@ -481,6 +481,8 @@ start: #endif if (*place == '-') { place++; /* --foo long option */ + if (*place == '\0') + return (BADARG); /* malformed option */ #ifdef GNU_COMPATIBLE dash_prefix = DD_PREFIX; #endif |