diff options
author | 2007-09-07 16:30:25 +0000 | |
---|---|---|
committer | 2007-09-07 16:30:25 +0000 | |
commit | 6bb8206276b5e35819d3113eb3ffa2ccaf34b3f6 (patch) | |
tree | 6e8e2b7b0ee75063bbc8753f358154a87e6bcb60 | |
parent | The obvious bzero/memset -> M_ZERO changes. (diff) | |
download | wireguard-openbsd-6bb8206276b5e35819d3113eb3ffa2ccaf34b3f6.tar.xz wireguard-openbsd-6bb8206276b5e35819d3113eb3ffa2ccaf34b3f6.zip |
check fgets return value
use sizeof buf instead of TP_BSIZE
use strcspn to properly overwrite '\n' in fgets returned buffer
ok moritz@ ray@
-rw-r--r-- | sbin/restore/tape.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 0120d703290..9cc2afe1316 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tape.c,v 1.33 2007/09/02 15:19:25 deraadt Exp $ */ +/* $OpenBSD: tape.c,v 1.34 2007/09/07 16:30:25 chl Exp $ */ /* $NetBSD: tape.c,v 1.26 1997/04/15 07:12:25 lukem Exp $ */ /* @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)tape.c 8.6 (Berkeley) 9/13/94"; #else -static const char rcsid[] = "$OpenBSD: tape.c,v 1.33 2007/09/02 15:19:25 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: tape.c,v 1.34 2007/09/07 16:30:25 chl Exp $"; #endif #endif /* not lint */ @@ -334,10 +334,10 @@ again: do { fprintf(stderr, "Specify next volume #: "); (void)fflush(stderr); - (void)fgets(buf, TP_BSIZE, terminal); - } while (!feof(terminal) && buf[0] == '\n'); - if (feof(terminal)) - exit(1); + if (fgets(buf, sizeof buf, terminal) == NULL || + feof(terminal)) + exit(1); + } while (buf[0] == '\n'); newvol = atoi(buf); if (newvol <= 0) { fprintf(stderr, @@ -353,11 +353,9 @@ again: fprintf(stderr, "Enter ``none'' if there are no more tapes\n"); fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape); (void)fflush(stderr); - if (fgets(buf, TP_BSIZE, terminal) == NULL || feof(terminal)) + if (fgets(buf, sizeof buf, terminal) == NULL || feof(terminal)) exit(1); - i = strlen(buf); - if (i > 0 && buf[--i] == '\n') - buf[i] = '\0'; + buf[strcspn(buf, "\n")] = '\0'; if (strcmp(buf, "none") == 0) { terminateinput(); return; |