From ad903dff1e670b3104d3b51be75a076e555088b7 Mon Sep 17 00:00:00 2001 From: tjr Date: Sat, 29 Jun 2002 05:31:26 +0000 Subject: Avoid truncating filenames with snprintf(). --- usr.bin/csplit/csplit.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'usr.bin/csplit') 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++; -- cgit v1.1