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)
Sun, Feb 9, 11:26 AM
Unknown Object (File)
Fri, Jan 24, 9:38 AM
Unknown Object (File)
Dec 13 2024, 1:20 PM
Unknown Object (File)
Dec 3 2024, 8:28 PM
Unknown Object (File)
Dec 2 2024, 7:38 PM
Unknown Object (File)
Nov 11 2024, 5:23 AM
Unknown Object (File)
Oct 9 2024, 7:08 AM
Unknown Object (File)
Sep 25 2024, 5:16 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.