summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornia <nia@NetBSD.org>2020-04-29 20:45:05 +0000
committernia <nia@NetBSD.org>2020-04-29 20:45:05 +0000
commit35f9239da17d9e247372b31eff7d50efb738dded (patch)
tree145901e933ba4871472bb90117c7c479be17b471
parent7890a8c64a29e8f0ee5b9b2ef41a118f9ac499bd (diff)
downloadbsdgames-darwin-35f9239da17d9e247372b31eff7d50efb738dded.tar.gz
bsdgames-darwin-35f9239da17d9e247372b31eff7d50efb738dded.tar.zst
bsdgames-darwin-35f9239da17d9e247372b31eff7d50efb738dded.zip
strfile: Check that input/output filenames don't exceed the buffer size
-rw-r--r--fortune/strfile/strfile.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/fortune/strfile/strfile.c b/fortune/strfile/strfile.c
index ae8f7b45..a0598505 100644
--- a/fortune/strfile/strfile.c
+++ b/fortune/strfile/strfile.c
@@ -1,4 +1,4 @@
-/* $NetBSD: strfile.c,v 1.38 2013/09/19 00:34:00 uwe Exp $ */
+/* $NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
#if 0
static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: strfile.c,v 1.38 2013/09/19 00:34:00 uwe Exp $");
+__RCSID("$NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $");
#endif
#endif /* not lint */
#endif /* __NetBSD__ */
@@ -267,6 +267,7 @@ getargs(int argc, char **argv)
int ch;
extern int optind;
extern char *optarg;
+ size_t len;
while ((ch = getopt(argc, argv, "c:iorsx")) != -1)
switch(ch) {
@@ -300,14 +301,25 @@ getargs(int argc, char **argv)
if (*argv) {
Infile = *argv;
- if (*++argv)
- (void) strcpy(Outfile, *argv);
+ if (*++argv) {
+ len = strlen(*argv);
+ if (len >= sizeof(Outfile)) {
+ puts("Bad output filename");
+ usage();
+ }
+ (void) memcpy(Outfile, *argv, len + 1);
+ }
}
if (!Infile) {
puts("No input file name");
usage();
}
if (*Outfile == '\0') {
+ len = strlen(Infile) + sizeof(".dat");
+ if (len > sizeof(Outfile)) {
+ puts("Bad input filename");
+ usage();
+ }
(void) strcpy(Outfile, Infile);
(void) strcat(Outfile, ".dat");
}