diff options
author | tjr <tjr@FreeBSD.org> | 2002-06-29 05:31:26 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-06-29 05:31:26 +0000 |
commit | ad903dff1e670b3104d3b51be75a076e555088b7 (patch) | |
tree | 5b34fc5b3992a41ad6291fa5cb0c261c7d6b9328 /usr.bin/csplit | |
parent | 2ca2fb4fa35657690af2afea3e3584496ee23ea8 (diff) | |
download | FreeBSD-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.c | 7 |
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++; |