util: fix gcc vsnprintf overflow

Anything higher than INT_MAX results in overflow although the parameter is declared as size_t.

Worse, with (size_t)-1 it is silently ignored and Woverflow is not emitted.

Closes #4226

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Tested-by: Prodea Alexandru-Liviu <liviuprodea@yahoo.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9134>
This commit is contained in:
Michel Zou
2021-02-18 17:20:22 +01:00
committed by Marge Bot
parent b6b3b38434
commit 34d6ce28e3

View File

@@ -42,6 +42,7 @@
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include "util/macros.h" // PRINTFLIKE
@@ -72,7 +73,7 @@ util_sprintf(char *str, const char *format, ...)
{
va_list ap;
va_start(ap, format);
vsnprintf(str, (size_t)-1, format, ap);
vsnprintf(str, INT_MAX, format, ap);
va_end(ap);
}