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
Unknown Object (File)
Fri, Dec 12, 3:56 AM
Unknown Object (File)
Thu, Nov 27, 5:42 AM
Unknown Object (File)
Mon, Nov 24, 7:58 PM
Unknown Object (File)
Fri, Nov 21, 12:36 AM
Unknown Object (File)
Fri, Nov 21, 12:36 AM
Unknown Object (File)
Fri, Nov 21, 12:33 AM
Unknown Object (File)
Fri, Nov 21, 12:29 AM
Unknown Object (File)
Nov 8 2025, 2:02 AM
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.