Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Dec 2014 20:26:12 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r275838 - head/usr.bin/sed
Message-ID:  <201412162026.sBGKQCr6089591@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Tue Dec 16 20:26:11 2014
New Revision: 275838
URL: https://svnweb.freebsd.org/changeset/base/275838

Log:
  sed: Bounds check the file path used in the 'w' command.
  
  Modified version of a diff from Sebastien Marie to prevent a crash found
  with the afl fuzzer.
  
  Obtained from:	OpenBSD (CVS Rev. 1.37)
  MFC after:	1 week

Modified:
  head/usr.bin/sed/compile.c

Modified: head/usr.bin/sed/compile.c
==============================================================================
--- head/usr.bin/sed/compile.c	Tue Dec 16 20:05:10 2014	(r275837)
+++ head/usr.bin/sed/compile.c	Tue Dec 16 20:26:11 2014	(r275838)
@@ -558,7 +558,7 @@ compile_flags(char *p, struct s_subst *s
 {
 	int gn;			/* True if we have seen g or n */
 	unsigned long nval;
-	char wfile[_POSIX2_LINE_MAX + 1], *q;
+	char wfile[_POSIX2_LINE_MAX + 1], *q, *eq;
 
 	s->n = 1;				/* Default */
 	s->p = 0;
@@ -611,9 +611,12 @@ compile_flags(char *p, struct s_subst *s
 #endif
 			EATSPACE();
 			q = wfile;
+			eq = wfile + sizeof(wfile) - 1;
 			while (*p) {
 				if (*p == '\n')
 					break;
+				if (q >= eq)
+					err(1, "wfile too long");
 				*q++ = *p++;
 			}
 			*q = '\0';



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