Date: Mon, 21 Jan 2019 02:59:37 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r343242 - stable/12/lib/libc/stdlib Message-ID: <201901210259.x0L2xbm0020036@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Mon Jan 21 02:59:37 2019 New Revision: 343242 URL: https://svnweb.freebsd.org/changeset/base/343242 Log: MFC r342757: getopt_long(3): fix case of malformed long opt 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. Modified: stable/12/lib/libc/stdlib/getopt_long.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libc/stdlib/getopt_long.c ============================================================================== --- stable/12/lib/libc/stdlib/getopt_long.c Mon Jan 21 02:57:57 2019 (r343241) +++ stable/12/lib/libc/stdlib/getopt_long.c Mon Jan 21 02:59:37 2019 (r343242) @@ -481,6 +481,8 @@ start: #endif if (*place == '-') { place++; /* --foo long option */ + if (*place == '\0') + return (BADARG); /* malformed option */ #ifdef GNU_COMPATIBLE dash_prefix = DD_PREFIX; #endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901210259.x0L2xbm0020036>