Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Jan 2019 03:13:25 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r342757 - head/lib/libc/stdlib
Message-ID:  <201901040313.x043DPFm094938@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Fri Jan  4 03:13:24 2019
New Revision: 342757
URL: https://svnweb.freebsd.org/changeset/base/342757

Log:
  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.
  
  Reported by:	Tony Overfield <toverfield@yahoo.com>
  Reviewed by:	imp
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D18616

Modified:
  head/lib/libc/stdlib/getopt_long.c

Modified: head/lib/libc/stdlib/getopt_long.c
==============================================================================
--- head/lib/libc/stdlib/getopt_long.c	Fri Jan  4 02:50:55 2019	(r342756)
+++ head/lib/libc/stdlib/getopt_long.c	Fri Jan  4 03:13:24 2019	(r342757)
@@ -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?201901040313.x043DPFm094938>