From 34d6ce28e380d48c8c42a6b52a9c39abba8d341a Mon Sep 17 00:00:00 2001 From: Michel Zou Date: Thu, 18 Feb 2021 17:20:22 +0100 Subject: [PATCH] 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 Tested-by: Prodea Alexandru-Liviu Part-of: --- src/util/u_string.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/u_string.h b/src/util/u_string.h index 88df2cc..4700d9c 100644 --- a/src/util/u_string.h +++ b/src/util/u_string.h @@ -42,6 +42,7 @@ #include #include #include +#include #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); } -- 2.7.4