Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Dec 2015 18:38:10 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@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: r292755 - stable/9/bin/ed
Message-ID:  <201512261838.tBQIcAeM025665@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sat Dec 26 18:38:09 2015
New Revision: 292755
URL: https://svnweb.freebsd.org/changeset/base/292755

Log:
  MFC	r292454, r292455
  ed(1): Prevent possible string overflows
  
  Use strlcpy to guarantee NULL termination.
  
  With hint from:	imp, cem, ngie
  CID:		1007252

Modified:
  stable/9/bin/ed/main.c
Directory Properties:
  stable/9/bin/ed/   (props changed)

Modified: stable/9/bin/ed/main.c
==============================================================================
--- stable/9/bin/ed/main.c	Sat Dec 26 18:37:01 2015	(r292754)
+++ stable/9/bin/ed/main.c	Sat Dec 26 18:38:09 2015	(r292755)
@@ -504,7 +504,8 @@ exec_command(void)
 			return ERR;
 		else if (open_sbuf() < 0)
 			return FATAL;
-		if (*fnp && *fnp != '!') strcpy(old_filename, fnp);
+		if (*fnp && *fnp != '!')
+			 strlcpy(old_filename, fnp, PATH_MAX);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
 			errmsg = "no current filename";
@@ -531,7 +532,8 @@ exec_command(void)
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
-		if (*fnp) strcpy(old_filename, fnp);
+		if (*fnp)
+			strlcpy(old_filename, fnp, PATH_MAX);
 		printf("%s\n", strip_escapes(old_filename));
 		break;
 	case 'g':
@@ -662,7 +664,7 @@ exec_command(void)
 		GET_COMMAND_SUFFIX();
 		if (!isglobal) clear_undo_stack();
 		if (*old_filename == '\0' && *fnp != '!')
-			strcpy(old_filename, fnp);
+			strlcpy(old_filename, fnp, PATH_MAX);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
 			errmsg = "no current filename";
@@ -796,7 +798,7 @@ exec_command(void)
 			return ERR;
 		GET_COMMAND_SUFFIX();
 		if (*old_filename == '\0' && *fnp != '!')
-			strcpy(old_filename, fnp);
+			strlcpy(old_filename, fnp, PATH_MAX);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
 			errmsg = "no current filename";



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