svn commit: r292754 - stable/10/bin/ed

Pedro F. Giffuni pfg at FreeBSD.org
Sat Dec 26 18:37:03 UTC 2015


Author: pfg
Date: Sat Dec 26 18:37:01 2015
New Revision: 292754
URL: https://svnweb.freebsd.org/changeset/base/292754

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/10/bin/ed/main.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/ed/main.c
==============================================================================
--- stable/10/bin/ed/main.c	Sat Dec 26 18:26:44 2015	(r292753)
+++ stable/10/bin/ed/main.c	Sat Dec 26 18:37:01 2015	(r292754)
@@ -505,7 +505,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";
@@ -532,7 +533,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':
@@ -663,7 +665,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";
@@ -797,7 +799,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 mailing list