summaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-08-23 06:11:01 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-08-23 06:11:01 +0000
commit6fe45b5a69219e652af854c028387f622eed93f3 (patch)
tree7bb026b41fccfe5f3fe7f619383656f0909a665e /games
parent158c0680614628c6622cd688d9f51724e1596158 (diff)
Check fgets for failure and do a proper newline strip.
Initial diff from Charles Longeau. OK otto and moritz.
Diffstat (limited to 'games')
-rw-r--r--games/banner/banner.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/games/banner/banner.c b/games/banner/banner.c
index 7f9069a696e..929ff748c77 100644
--- a/games/banner/banner.c
+++ b/games/banner/banner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: banner.c,v 1.13 2006/11/22 19:31:39 otto Exp $ */
+/* $OpenBSD: banner.c,v 1.14 2007/08/23 06:11:00 ray Exp $ */
/* $NetBSD: banner.c,v 1.4 1995/04/22 11:55:15 cgd Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)banner.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: banner.c,v 1.13 2006/11/22 19:31:39 otto Exp $";
+static char rcsid[] = "$OpenBSD: banner.c,v 1.14 2007/08/23 06:11:00 ray Exp $";
#endif
#endif /* not lint */
@@ -1064,14 +1064,15 @@ main(int argc, char *argv[])
strlcat(message, " ", sizeof message);
strlcat(message, *argv, sizeof message);
}
- nchars = strlen(message);
} else {
if (isatty(fileno(stdin)))
fprintf(stderr,"Message: ");
- (void)fgets(message, sizeof(message), stdin);
- nchars = strlen(message);
- message[nchars--] = '\0'; /* get rid of newline */
+ if (fgets(message, sizeof(message), stdin) == NULL)
+ errx(1, "error reading message");
+ /* get rid of newline */
+ message[strcspn(message, "\n")] = '\0';
}
+ nchars = strlen(message);
/* some debugging print statements */
if (debug) {