diff options
author | tjr <tjr@FreeBSD.org> | 2002-11-01 11:53:52 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-11-01 11:53:52 +0000 |
commit | f6cc8ac57049a95b8a5c604f3886779bbc75e022 (patch) | |
tree | c154edbabeec317d2c444e8f2d373f7e03f69284 /usr.bin/mkstr | |
parent | 8818a9353d7a3d980b8b52b1120b1a62d833222e (diff) | |
download | FreeBSD-src-f6cc8ac57049a95b8a5c604f3886779bbc75e022.zip FreeBSD-src-f6cc8ac57049a95b8a5c604f3886779bbc75e022.tar.gz |
Avoid buffer overflow when constructing filenames.
Diffstat (limited to 'usr.bin/mkstr')
-rw-r--r-- | usr.bin/mkstr/mkstr.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/mkstr/mkstr.c b/usr.bin/mkstr/mkstr.c index f2d2b61..ab87c73 100644 --- a/usr.bin/mkstr/mkstr.c +++ b/usr.bin/mkstr/mkstr.c @@ -47,6 +47,7 @@ static char sccsid[] = "@(#)mkstr.c 8.1 (Berkeley) 6/6/93"; __FBSDID("$FreeBSD$"); #include <err.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -95,6 +96,7 @@ int main(int argc, char *argv[]) { char addon = 0; + size_t namelen; argc--, argv++; if (argc > 1 && argv[0][0] == '-') @@ -109,11 +111,19 @@ main(int argc, char *argv[]) err(1, "%s", argv[0]); inithash(); argc--, argv++; - strcpy(name, argv[0]); - np = name + strlen(name); + namelen = strlcpy(name, argv[0], sizeof(name)); + if (namelen >= sizeof(name)) { + errno = ENAMETOOLONG; + err(1, "%s", argv[0]); + } + np = name + namelen; argc--, argv++; do { - strcpy(np, argv[0]); + if (strlcpy(np, argv[0], sizeof(name) - namelen) >= + sizeof(name) - namelen) { + errno = ENAMETOOLONG; + err(1, "%s%s", name, argv[0]); + } if (freopen(name, "w", stdout) == NULL) err(1, "%s", name); if (freopen(argv[0], "r", stdin) == NULL) |