svn commit: r292755 - stable/9/bin/ed

Pedro F. Giffuni pfg at FreeBSD.org
Sat Dec 26 18:38:11 UTC 2015


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";


More information about the svn-src-stable-9 mailing list