ed(1): Prevent possible string overflows

CID:		1007252
MFC after:	2 weeks
This commit is contained in:
Pedro F. Giffuni 2015-12-18 21:58:42 +00:00
parent f8fd13a099
commit bebd99b272
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=292454

View File

@ -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 != '!')
strncpy(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)
strncpy(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);
strncpy(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);
strncpy(old_filename, fnp, PATH_MAX);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
errmsg = "no current filename";