Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Dec 2015 23:05:36 +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: r292455 - head/bin/ed
Message-ID:  <201512182305.tBIN5aY1060923@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Fri Dec 18 23:05:36 2015
New Revision: 292455
URL: https://svnweb.freebsd.org/changeset/base/292455

Log:
  ed(1): Prevent possible string overflows
  
  Use strlcpy instead of strncpy to guarantee NULL termination.
  
  Pointed out by:	imp
  CID:		1007252
  X-MFC with:	r292454

Modified:
  head/bin/ed/main.c

Modified: head/bin/ed/main.c
==============================================================================
--- head/bin/ed/main.c	Fri Dec 18 21:58:42 2015	(r292454)
+++ head/bin/ed/main.c	Fri Dec 18 23:05:36 2015	(r292455)
@@ -506,7 +506,7 @@ exec_command(void)
 		else if (open_sbuf() < 0)
 			return FATAL;
 		if (*fnp && *fnp != '!')
-			 strncpy(old_filename, fnp, PATH_MAX);
+			 strlcpy(old_filename, fnp, PATH_MAX);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
 			errmsg = "no current filename";
@@ -534,7 +534,7 @@ exec_command(void)
 		}
 		GET_COMMAND_SUFFIX();
 		if (*fnp)
-			strncpy(old_filename, fnp, PATH_MAX);
+			strlcpy(old_filename, fnp, PATH_MAX);
 		printf("%s\n", strip_escapes(old_filename));
 		break;
 	case 'g':
@@ -665,7 +665,7 @@ exec_command(void)
 		GET_COMMAND_SUFFIX();
 		if (!isglobal) clear_undo_stack();
 		if (*old_filename == '\0' && *fnp != '!')
-			strncpy(old_filename, fnp, PATH_MAX);
+			strlcpy(old_filename, fnp, PATH_MAX);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
 			errmsg = "no current filename";
@@ -799,7 +799,7 @@ exec_command(void)
 			return ERR;
 		GET_COMMAND_SUFFIX();
 		if (*old_filename == '\0' && *fnp != '!')
-			strncpy(old_filename, fnp, PATH_MAX);
+			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?201512182305.tBIN5aY1060923>