Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Dec 2015 18:37:01 +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-10@freebsd.org
Subject:   svn commit: r292754 - stable/10/bin/ed
Message-ID:  <201512261837.tBQIb18J025570@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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";



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