svn commit: r343242 - stable/12/lib/libc/stdlib

Kyle Evans kevans at FreeBSD.org
Mon Jan 21 02:59:38 UTC 2019


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


More information about the svn-src-all mailing list