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:
@@ -42,6 +42,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "util/macros.h" // PRINTFLIKE
|
#include "util/macros.h" // PRINTFLIKE
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ util_sprintf(char *str, const char *format, ...)
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
vsnprintf(str, (size_t)-1, format, ap);
|
vsnprintf(str, INT_MAX, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user