From bebd99b272cacd4e7d11396a03b018e635a2e13c Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Fri, 18 Dec 2015 21:58:42 +0000 Subject: [PATCH] ed(1): Prevent possible string overflows CID: 1007252 MFC after: 2 weeks --- bin/ed/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/ed/main.c b/bin/ed/main.c index 98bb300fe623..138c183ef98c 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 != '!') + 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";