From: Ngie Cooper Date: Tue, 13 Dec 2016 07:03:27 +0000 (-0800) Subject: In the event the heap allocation fails after a successful allocation, X-Git-Tag: v3.3.0~36^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7b12fad8d80133a2aef6a72e4abc3439e6c6ec9;p=thirdparty%2Flibarchive.git In the event the heap allocation fails after a successful allocation, restore fmtbuff back to fmtbuff_stack, per the intent of the else condition Otherwise, there's a chance that fmtbuff used after the mbtowc call is using an invalid buffer, as fmtbuff_heap has been already free'd. Reported by: Coverity CID: 1006126 --- diff --git a/tar/util.c b/tar/util.c index 2b4aebe8e..8f65b1762 100644 --- a/tar/util.c +++ b/tar/util.c @@ -140,6 +140,7 @@ safe_fprintf(FILE *f, const char *fmt, ...) } else { /* Leave fmtbuff pointing to the truncated * string in fmtbuff_stack. */ + fmtbuff = fmtbuff_stack; length = sizeof(fmtbuff_stack) - 1; break; }