Skip to content

Commit

Permalink
ed(1): Prevent possible string overflows
Browse files Browse the repository at this point in the history
CID:		1007252
MFC after:	2 weeks
  • Loading branch information
pgiffuni committed Dec 18, 2015
1 parent f8fd13a commit bebd99b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bin/ed/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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':
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit bebd99b

Please sign in to comment.