summaryrefslogtreecommitdiffstats
path: root/bin/ed/main.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2015-12-26 18:37:01 +0000
committerpfg <pfg@FreeBSD.org>2015-12-26 18:37:01 +0000
commit1ee182fa5f4a0ca44fe9d5fa12b6aabd54173fe7 (patch)
treefeaadf346a93ed1d4a88cff547cf39c02a8d3272 /bin/ed/main.c
parentc41fd18fc06371fed84c5d6dce7ba85695860b6e (diff)
downloadFreeBSD-src-1ee182fa5f4a0ca44fe9d5fa12b6aabd54173fe7.zip
FreeBSD-src-1ee182fa5f4a0ca44fe9d5fa12b6aabd54173fe7.tar.gz
MFC r292454, r292455
ed(1): Prevent possible string overflows Use strlcpy to guarantee NULL termination. With hint from: imp, cem, ngie CID: 1007252
Diffstat (limited to 'bin/ed/main.c')
-rw-r--r--bin/ed/main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/bin/ed/main.c b/bin/ed/main.c
index 98bb300..1749314 100644
--- a/bin/ed/main.c
+++ b/bin/ed/main.c
@@ -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";
OpenPOWER on IntegriCloud