summaryrefslogtreecommitdiff
path: root/usr.bin/banner
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>1999-12-04 02:11:51 +0000
committerKris Kennaway <kris@FreeBSD.org>1999-12-04 02:11:51 +0000
commit1b2fef9f1ef253fee2ebb5a7f1ff19fadc452920 (patch)
tree4e2c380cd38de6d38658bca157f9265eac7d22f4 /usr.bin/banner
parent2963da13bf7b5df4a358a2a9b10e4721bf375cdd (diff)
downloadsrc-test2-1b2fef9f1ef253fee2ebb5a7f1ff19fadc452920.tar.gz
src-test2-1b2fef9f1ef253fee2ebb5a7f1ff19fadc452920.zip
Fix buffer overflow & add $FreeBSD$
Reviewed by: imp
Notes
Notes: svn path=/head/; revision=54110
Diffstat (limited to 'usr.bin/banner')
-rw-r--r--usr.bin/banner/banner.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/banner/banner.c b/usr.bin/banner/banner.c
index e516f57f60cc..804f0365b961 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);
}