HomeFreeBSD

getopt_long(3): fix case of malformed long opt

Description

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

Details

Provenance
kevansAuthored on
Reviewer
imp
Differential Revision
D18616: getopt_long: fix case of malformed long opt
Parents
rS342756: MFC r342218:
Branches
Unknown
Tags
Unknown