]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tar: Make safe_fprintf more platform independent 2609/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 16 May 2025 22:01:53 +0000 (00:01 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 16 May 2025 22:23:01 +0000 (00:23 +0200)
If vsnprintf fails with errno EOVERFLOW, the results are very platform
dependent but never useful. The implementation in glibc fills bytes with
blanks, FreeBSD fills them with zeros, OpenBSD and Windows set first
byte to '\0'.

Just stop processing and don't print anything, which makes it follow
the OpenBSD and Windows approach.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
tar/util.c

index 1321a6839793c739e5f2f11cf8e25883f19dfc46..c99f67797562c515025eb38bbff498bf5ef5b684 100644 (file)
@@ -96,6 +96,10 @@ safe_fprintf(FILE * restrict f, const char * restrict fmt, ...)
        length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap);
        va_end(ap);
 
+       /* If vsnprintf will always fail, stop early. */
+       if (length < 0 && errno == EOVERFLOW)
+               return;
+
        /* If the result was too large, allocate a buffer on the heap. */
        while (length < 0 || (size_t)length >= fmtbuff_length) {
                if (length >= 0 && (size_t)length >= fmtbuff_length)