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
This commit is contained in:
parent
07372194c3
commit
253b638eab
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=342757
@ -481,6 +481,8 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
|
||||
#endif
|
||||
if (*place == '-') {
|
||||
place++; /* --foo long option */
|
||||
if (*place == '\0')
|
||||
return (BADARG); /* malformed option */
|
||||
#ifdef GNU_COMPATIBLE
|
||||
dash_prefix = DD_PREFIX;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user