Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Aug 2016 18:53:57 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r303883 - in stable/9/usr.bin/grep: . regex
Message-ID:  <201608091853.u79Irvo3054344@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Tue Aug  9 18:53:57 2016
New Revision: 303883
URL: https://svnweb.freebsd.org/changeset/base/303883

Log:
  MFC r228395 (by ed):
  
  Add missing "static const" to long options table.
  
  This table is only used in this C file and passed to getopt_long(), so
  we can safely add static and const to it.
  
  MFC r241737 (by ed):
  
  More -Wmissing-variable-declarations fixes.
  
  MFC r270132 (by gabor):
  
  - Do not look for more matching lines if -L is specified
  
  Submitted by:   eadler (based on)
  
  MFC r296799 (by ian):
  
  Fix a bug in bsdgrep that caused the program to hang in a tight loop for
  some combinations of command line options and search patterns.  The code was
  examining regexec flags looking for a regcomp flag value.  The fix is to
  look in the struct field where the decoded regcomp flag was stored when the
  regex was compiled.
  
  With this fix, it's possible to build WITHOUT_GNU_GREP_COMPAT and
  WITH_BSDGREP and have a usable GPL-free grep (which of course lacks gnugrep
  extensions).  It now passes the kyua tests except for one test that requires
  the -z/--null-data gnu extension, and one test involving outputting context
  lines across multiple files which appears to sometimes output an extra
  delimiter line ("--") between matches (a rather obscure failure of a rather
  obscure feature, so bsdgrep should be generally usable now).
  
  MFC r303676:
  
  Fix a segfault in bsdgrep when parsing the invalid extended regexps "?"
  or "+" (these are invalid, because there is no preceding operand).
  
  When bsdgrep attempts to emulate GNU grep in discarding and ignoring the
  invalid ? or + operators, some later logic in tre_compile_fast() goes
  beyond the end of the buffer, leading to a crash.
  
  Fix this by bailing out, and reporting a bad pattern instead.
  
  Reported by:	Steve Kargl

Modified:
  stable/9/usr.bin/grep/grep.c
  stable/9/usr.bin/grep/regex/glue.h
  stable/9/usr.bin/grep/regex/tre-fastmatch.c
  stable/9/usr.bin/grep/regex/xmalloc.c
  stable/9/usr.bin/grep/util.c
Directory Properties:
  stable/9/usr.bin/grep/   (props changed)

Modified: stable/9/usr.bin/grep/grep.c
==============================================================================
--- stable/9/usr.bin/grep/grep.c	Tue Aug  9 18:49:19 2016	(r303882)
+++ stable/9/usr.bin/grep/grep.c	Tue Aug  9 18:53:57 2016	(r303883)
@@ -83,14 +83,15 @@ int		 eflags = REG_STARTEND;
 bool		 matchall;
 
 /* Searching patterns */
-unsigned int	 patterns, pattern_sz;
+unsigned int	 patterns;
+static unsigned int pattern_sz;
 struct pat	*pattern;
 regex_t		*r_pattern;
 fastmatch_t	*fg_pattern;
 
 /* Filename exclusion/inclusion patterns */
-unsigned int	 fpatterns, fpattern_sz;
-unsigned int	 dpatterns, dpattern_sz;
+unsigned int	fpatterns, dpatterns;
+static unsigned int fpattern_sz, dpattern_sz;
 struct epat	*dpattern, *fpattern;
 
 /* For regex errors  */
@@ -167,7 +168,7 @@ usage(void)
 
 static const char	*optstr = "0123456789A:B:C:D:EFGHIJMLOPSRUVZabcd:e:f:hilm:nopqrsuvwxXy";
 
-struct option long_options[] =
+static const struct option long_options[] =
 {
 	{"binary-files",	required_argument,	NULL, BIN_OPT},
 	{"help",		no_argument,		NULL, HELP_OPT},

Modified: stable/9/usr.bin/grep/regex/glue.h
==============================================================================
--- stable/9/usr.bin/grep/regex/glue.h	Tue Aug  9 18:49:19 2016	(r303882)
+++ stable/9/usr.bin/grep/regex/glue.h	Tue Aug  9 18:53:57 2016	(r303883)
@@ -50,7 +50,7 @@ typedef enum { STR_WIDE, STR_BYTE, STR_M
       if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0)		\
 	return REG_NOMATCH;						\
       ret = fn;								\
-      for (unsigned i = 0; (!(eflags & REG_NOSUB) && (i < nmatch)); i++)\
+      for (unsigned i = 0; (!preg->nosub && (i < nmatch)); i++)		\
 	{								\
 	  pmatch[i].rm_so += offset;					\
 	  pmatch[i].rm_eo += offset;					\

Modified: stable/9/usr.bin/grep/regex/tre-fastmatch.c
==============================================================================
--- stable/9/usr.bin/grep/regex/tre-fastmatch.c	Tue Aug  9 18:49:19 2016	(r303882)
+++ stable/9/usr.bin/grep/regex/tre-fastmatch.c	Tue Aug  9 18:53:57 2016	(r303883)
@@ -621,7 +621,7 @@ tre_compile_fast(fastmatch_t *fg, const 
 	  case TRE_CHAR('+'):
 	  case TRE_CHAR('?'):
 	    if ((cflags & REG_EXTENDED) && (i == 0))
-	      continue;
+	      goto badpat;
 	    else if ((cflags & REG_EXTENDED) ^ !escaped)
 	      STORE_CHAR;
 	    else

Modified: stable/9/usr.bin/grep/regex/xmalloc.c
==============================================================================
--- stable/9/usr.bin/grep/regex/xmalloc.c	Tue Aug  9 18:49:19 2016	(r303882)
+++ stable/9/usr.bin/grep/regex/xmalloc.c	Tue Aug  9 18:53:57 2016	(r303883)
@@ -39,9 +39,9 @@ typedef struct {
 } hashTable;
 
 static int xmalloc_peak;
-int xmalloc_current;
+static int xmalloc_current;
 static int xmalloc_peak_blocks;
-int xmalloc_current_blocks;
+static int xmalloc_current_blocks;
 static int xmalloc_fail_after;
 
 #define TABLE_BITS 8

Modified: stable/9/usr.bin/grep/util.c
==============================================================================
--- stable/9/usr.bin/grep/util.c	Tue Aug  9 18:49:19 2016	(r303882)
+++ stable/9/usr.bin/grep/util.c	Tue Aug  9 18:53:57 2016	(r303883)
@@ -336,7 +336,7 @@ procline(struct str *l, int nottext)
 		}
 
 		/* One pass if we are not recording matches */
-		if (!wflag && ((color == NULL && !oflag) || qflag || lflag))
+		if (!wflag && ((color == NULL && !oflag) || qflag || lflag || Lflag))
 			break;
 
 		if (st == (size_t)pmatch.rm_so)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608091853.u79Irvo3054344>