diff options
author | pfg <pfg@FreeBSD.org> | 2015-12-18 23:05:36 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-12-18 23:05:36 +0000 |
commit | 690479eac41bea3965d72f8f50f29dc4576b616c (patch) | |
tree | 8447d61ce0b26c9604c55d494d241c2357a316aa | |
parent | 0ba92f8ec128fc6965986160d6115ebd38484371 (diff) | |
download | FreeBSD-src-690479eac41bea3965d72f8f50f29dc4576b616c.zip FreeBSD-src-690479eac41bea3965d72f8f50f29dc4576b616c.tar.gz |
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
-rw-r--r-- | bin/ed/main.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/bin/ed/main.c b/bin/ed/main.c index 138c183..1749314 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -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"; |