summaryrefslogtreecommitdiffstats
path: root/usr.bin/csplit
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-29 05:31:26 +0000
committertjr <tjr@FreeBSD.org>2002-06-29 05:31:26 +0000
commitad903dff1e670b3104d3b51be75a076e555088b7 (patch)
tree5b34fc5b3992a41ad6291fa5cb0c261c7d6b9328 /usr.bin/csplit
parent2ca2fb4fa35657690af2afea3e3584496ee23ea8 (diff)
downloadFreeBSD-src-ad903dff1e670b3104d3b51be75a076e555088b7.zip
FreeBSD-src-ad903dff1e670b3104d3b51be75a076e555088b7.tar.gz
Avoid truncating filenames with snprintf().
Diffstat (limited to 'usr.bin/csplit')
-rw-r--r--usr.bin/csplit/csplit.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/usr.bin/csplit/csplit.c b/usr.bin/csplit/csplit.c
index 5513f7b..dfc8f5b 100644
--- a/usr.bin/csplit/csplit.c
+++ b/usr.bin/csplit/csplit.c
@@ -227,8 +227,11 @@ newfile(void)
{
FILE *fp;
- snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix, (int)sufflen,
- nfiles);
+ if (snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix,
+ (int)sufflen, nfiles) >= sizeof(currfile)) {
+ errno = ENAMETOOLONG;
+ err(1, NULL);
+ }
if ((fp = fopen(currfile, "w+")) == NULL)
err(1, "%s", currfile);
nfiles++;
OpenPOWER on IntegriCloud