diff --git a/sbin/restore/main.c b/sbin/restore/main.c index 6eba6954b6e..4865e94eeb1 100644 --- a/sbin/restore/main.c +++ b/sbin/restore/main.c @@ -344,11 +344,12 @@ obsolete(int *argcp, char **argvp[]) warnx("option requires an argument -- %c", *ap); usage(); } - if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL) + size_t len = strlen(*argv); + if ((nargv[0] = malloc(len + 2 + 1)) == NULL) err(1, NULL); nargv[0][0] = '-'; nargv[0][1] = *ap; - (void)strcpy(&nargv[0][2], *argv); + memcpy(&nargv[0][2], *argv, len + 1); ++argv; ++nargv; break; diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index c3fe0d7d8b0..83598222aeb 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -398,7 +398,11 @@ again: return; } if (buf[0] != '\n') { - (void) strcpy(magtape, buf); + free(magtape); + if ((magtape = strdup(buf)) == NULL) { + fprintf(stderr, "Cannot allocate space for tape name\n"); + done(1); + } magtape[strlen(magtape) - 1] = '\0'; } if (pipecmdin) {