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, Nov 11, 5:23 AM
Unknown Object (File)
Oct 9 2024, 7:08 AM
Unknown Object (File)
Sep 25 2024, 5:16 PM
Unknown Object (File)
Sep 19 2024, 6:30 AM
Unknown Object (File)
Sep 5 2024, 12:51 AM
Unknown Object (File)
Aug 27 2024, 2:04 AM
Unknown Object (File)
Aug 22 2024, 5:32 PM
Unknown Object (File)
Aug 21 2024, 3:22 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.