summaryrefslogtreecommitdiff
path: root/sbin/restore
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2007-09-25 09:51:49 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2007-09-25 09:51:49 +0000
commitb641a8cf4859a2eb468bc77f6ce98a4b7eeeb759 (patch)
tree2f4d9edb1a5c376671275cab3fe8e4198a5c10df /sbin/restore
parent10a716ca1f18acf8d8d53db3223fe30b7e85a2fc (diff)
check fgets return value
use sizeof input intead of BUFSIZ remove unneeded feof handle empty strings returned by fgets properly remove newline and white space at the end of buffer with help and ok ray@
Diffstat (limited to 'sbin/restore')
-rw-r--r--sbin/restore/interactive.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c
index 860de17dab2..3eb1eb99511 100644
--- a/sbin/restore/interactive.c
+++ b/sbin/restore/interactive.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interactive.c,v 1.24 2007/09/02 15:19:25 deraadt Exp $ */
+/* $OpenBSD: interactive.c,v 1.25 2007/09/25 09:51:48 chl Exp $ */
/* $NetBSD: interactive.c,v 1.10 1997/03/19 08:42:52 lukem Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)interactive.c 8.3 (Berkeley) 9/13/94";
#else
-static const char rcsid[] = "$OpenBSD: interactive.c,v 1.24 2007/09/02 15:19:25 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: interactive.c,v 1.25 2007/09/25 09:51:48 chl Exp $";
#endif
#endif /* not lint */
@@ -327,13 +327,13 @@ getcmd(char *curdir, char *cmd, size_t cmdlen, char *name, size_t namelen,
do {
(void)fprintf(stderr, "%s > ", __progname);
(void)fflush(stderr);
- (void)fgets(input, BUFSIZ, terminal);
- } while (!feof(terminal) && input[0] == '\n');
- if (feof(terminal)) {
- (void)strlcpy(cmd, "quit", cmdlen);
- return;
- }
- for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--)
+ if (fgets(input, sizeof input, terminal) == NULL) {
+ (void)strlcpy(cmd, "quit", cmdlen);
+ return;
+ }
+ } while (input[0] == '\n' || input[0] == '\0');
+ for (cp = &input[strlen(input) - 1];
+ cp >= input && (*cp == ' ' || *cp == '\t' || *cp == '\n'); cp--)
/* trim off trailing white space and newline */;
*++cp = '\0';
/*