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
This commit is contained in:
parent
0ba92f8ec1
commit
690479eac4
@ -506,7 +506,7 @@ exec_command(void)
|
|||||||
else if (open_sbuf() < 0)
|
else if (open_sbuf() < 0)
|
||||||
return FATAL;
|
return FATAL;
|
||||||
if (*fnp && *fnp != '!')
|
if (*fnp && *fnp != '!')
|
||||||
strncpy(old_filename, fnp, PATH_MAX);
|
strlcpy(old_filename, fnp, PATH_MAX);
|
||||||
#ifdef BACKWARDS
|
#ifdef BACKWARDS
|
||||||
if (*fnp == '\0' && *old_filename == '\0') {
|
if (*fnp == '\0' && *old_filename == '\0') {
|
||||||
errmsg = "no current filename";
|
errmsg = "no current filename";
|
||||||
@ -534,7 +534,7 @@ exec_command(void)
|
|||||||
}
|
}
|
||||||
GET_COMMAND_SUFFIX();
|
GET_COMMAND_SUFFIX();
|
||||||
if (*fnp)
|
if (*fnp)
|
||||||
strncpy(old_filename, fnp, PATH_MAX);
|
strlcpy(old_filename, fnp, PATH_MAX);
|
||||||
printf("%s\n", strip_escapes(old_filename));
|
printf("%s\n", strip_escapes(old_filename));
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
@ -665,7 +665,7 @@ exec_command(void)
|
|||||||
GET_COMMAND_SUFFIX();
|
GET_COMMAND_SUFFIX();
|
||||||
if (!isglobal) clear_undo_stack();
|
if (!isglobal) clear_undo_stack();
|
||||||
if (*old_filename == '\0' && *fnp != '!')
|
if (*old_filename == '\0' && *fnp != '!')
|
||||||
strncpy(old_filename, fnp, PATH_MAX);
|
strlcpy(old_filename, fnp, PATH_MAX);
|
||||||
#ifdef BACKWARDS
|
#ifdef BACKWARDS
|
||||||
if (*fnp == '\0' && *old_filename == '\0') {
|
if (*fnp == '\0' && *old_filename == '\0') {
|
||||||
errmsg = "no current filename";
|
errmsg = "no current filename";
|
||||||
@ -799,7 +799,7 @@ exec_command(void)
|
|||||||
return ERR;
|
return ERR;
|
||||||
GET_COMMAND_SUFFIX();
|
GET_COMMAND_SUFFIX();
|
||||||
if (*old_filename == '\0' && *fnp != '!')
|
if (*old_filename == '\0' && *fnp != '!')
|
||||||
strncpy(old_filename, fnp, PATH_MAX);
|
strlcpy(old_filename, fnp, PATH_MAX);
|
||||||
#ifdef BACKWARDS
|
#ifdef BACKWARDS
|
||||||
if (*fnp == '\0' && *old_filename == '\0') {
|
if (*fnp == '\0' && *old_filename == '\0') {
|
||||||
errmsg = "no current filename";
|
errmsg = "no current filename";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user