diff options
| author | christos <christos@NetBSD.org> | 2006-06-11 16:15:20 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2006-06-11 16:15:20 +0000 |
| commit | 460f8d8a0cf47e462bb4addfab9e5491dc44e1ba (patch) | |
| tree | 10166aefd0cfbaf24527fba307f44b5d7c103faf /bin/ed | |
| parent | e1168b95640e7f2e98345f497aeaa7916a207710 (diff) | |
PR/33699: Kevin Massey: use strlcpy to prevent stack overflows.
Diffstat (limited to 'bin/ed')
| -rw-r--r-- | bin/ed/main.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/bin/ed/main.c b/bin/ed/main.c index c7282cc8e4e..8e3483a60a2 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.17 2005/06/26 19:10:49 christos Exp $ */ +/* $NetBSD: main.c,v 1.18 2006/06/11 16:15:20 christos Exp $ */ /* main.c: This file contains the main control and user-interface routines for the ed line editor. */ @@ -39,7 +39,7 @@ __COPYRIGHT( #if 0 static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp"; #else -__RCSID("$NetBSD: main.c,v 1.17 2005/06/26 19:10:49 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.18 2006/06/11 16:15:20 christos Exp $"); #endif #endif /* not lint */ @@ -177,7 +177,8 @@ top: if (read_file(*argv, 0) < 0 && !isatty(0)) quit(2); else if (**argv != '!') - strcpy(old_filename, *argv); + strlcpy(old_filename, *argv, + sizeof(old_filename) - 2); } else if (argc) { fputs("?\n", stderr); if (**argv == '\0') @@ -510,7 +511,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, + sizeof(old_filename) - 2); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { sprintf(errmsg, "no current filename"); @@ -537,7 +539,7 @@ exec_command(void) return ERR; } GET_COMMAND_SUFFIX(); - if (*fnp) strcpy(old_filename, fnp); + if (*fnp) strlcpy(old_filename, fnp, sizeof(old_filename) - 2); printf("%s\n", strip_escapes(old_filename)); break; case 'g': @@ -668,7 +670,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, sizeof(old_filename) - 2); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { sprintf(errmsg, "no current filename"); @@ -802,7 +804,7 @@ exec_command(void) return ERR; GET_COMMAND_SUFFIX(); if (*old_filename == '\0' && *fnp != '!') - strcpy(old_filename, fnp); + strlcpy(old_filename, fnp, sizeof(old_filename) - 2); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { sprintf(errmsg, "no current filename"); |
