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)
Mon, Apr 15, 5:55 AM
Unknown Object (File)
Mon, Apr 15, 5:37 AM
Unknown Object (File)
Mar 8 2024, 12:01 AM
Unknown Object (File)
Feb 8 2024, 8:57 AM
Unknown Object (File)
Jan 12 2024, 10:14 AM
Unknown Object (File)
Jan 5 2024, 1:06 PM
Unknown Object (File)
Dec 16 2023, 6:27 AM
Unknown Object (File)
Oct 27 2023, 8:03 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.