diff options
author | kris <kris@FreeBSD.org> | 1999-12-04 02:11:51 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 1999-12-04 02:11:51 +0000 |
commit | 885348587c637132608fab3eb33a6fb8e238561e (patch) | |
tree | 07acdddf40e281e02fff19c09558fc980261a8dc /usr.bin/banner | |
parent | b6b57faeef807ca8b13a23e047d8479ab962044b (diff) | |
download | FreeBSD-src-885348587c637132608fab3eb33a6fb8e238561e.zip FreeBSD-src-885348587c637132608fab3eb33a6fb8e238561e.tar.gz |
Fix buffer overflow & add $FreeBSD$
Reviewed by: imp
Diffstat (limited to 'usr.bin/banner')
-rw-r--r-- | usr.bin/banner/banner.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/banner/banner.c b/usr.bin/banner/banner.c index e516f57..804f036 100644 --- a/usr.bin/banner/banner.c +++ b/usr.bin/banner/banner.c @@ -38,7 +38,11 @@ static const char copyright[] = #endif /* not lint */ #ifndef lint +#if 0 static const char sccsid[] = "@(#)banner.c 8.4 (Berkeley) 4/29/95"; +#endif +static const char rcsid[] = + "$FreeBSD$"; #endif /* not lint */ /* @@ -1018,7 +1022,7 @@ const char data_table[NBYTES] = { }; char line[DWIDTH]; -char message[MAXMSG]; +char *message; char print[DWIDTH]; int debug, i, j, linen, max, nchars, pc, term, trace, x, y; int width = DWIDTH; /* -w option: scrunch letters to 80 columns */ @@ -1058,6 +1062,10 @@ main(argc, argv) /* Have now read in the data. Next get the message to be printed. */ if (*argv) { + for(i=0, j=0; i < argc; i++) + j += strlen(argv[i]) + (i != 0); + if ((message = malloc(j)) == NULL) + err(1, "malloc"); strcpy(message, *argv); while (*++argv) { strcat(message, " "); @@ -1065,8 +1073,10 @@ main(argc, argv) } nchars = strlen(message); } else { + if ((message = malloc(MAXMSG)) == NULL) + err(1, "malloc"); fprintf(stderr,"Message: "); - (void)fgets(message, sizeof(message), stdin); + (void)fgets(message, MAXMSG, stdin); nchars = strlen(message); message[nchars--] = '\0'; /* get rid of newline */ } @@ -1156,5 +1166,6 @@ main(argc, argv) } } + free(message); exit(0); } |