Page MenuHomeFreeBSD

getopt_long: fix case of malformed long opt
ClosedPublic

Authored by kevans on Dec 20 2018, 2:02 AM.
Tags
None
Referenced Files
F170173569: D18616.id52187.diff
Thu, Sep 3, 5:53 PM
F169867905: D18616.id52540.diff
Wed, Sep 2, 8:18 PM
Unknown Object (File)
Wed, Sep 2, 2:05 PM
Unknown Object (File)
Wed, Sep 2, 8:43 AM
Unknown Object (File)
Wed, Sep 2, 7:03 AM
Unknown Object (File)
Tue, Sep 1, 5:40 PM
Unknown Object (File)
Mon, Aug 31, 3:32 PM
Unknown Object (File)
Mon, Aug 31, 2:20 PM
Subscribers

Details

Summary

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>

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Dec 20 2018, 3:35 AM

I guess I failed to mention: Tony's original report was that ls -l- is triggered ls's COLOR_OPT processing (https://svnweb.freebsd.org/base/head/bin/ls/ls.c?revision=338028&view=markup#l435) -- which is clearly wrong based on the context.

This revision was automatically updated to reflect the committed changes.