From b7b12fad8d80133a2aef6a72e4abc3439e6c6ec9 Mon Sep 17 00:00:00 2001 From: Ngie Cooper Date: Mon, 12 Dec 2016 23:03:27 -0800 Subject: [PATCH] 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 --- tar/util.c | 1 + 1 file changed, 1 insertion(+) 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; } -- 2.47.3