gprintf: Fix invalid size allocation in `g_vasprintf()`
As per the previous commit, it’s possible for
g_printf_string_upper_bound()
to return an error. We need to catch and
handle that error in g_vasprintf()
to avoid it trying to write to a
NULL
string allocation and crashing.
So, call g_vsnprintf()
directly instead of calling
g_printf_string_upper_bound()
, so that the error case can be handled.
There was already a test for some of this behaviour
(test_vasprintf_invalid_format_placeholder()
). Because it tested an
invalid format string, the _g_vsprintf()
call bailed out before
checking whether the buffer it had been passed was NULL
. The new test
has a valid format string, but an invalid arg.
When running the tests locally, I have disabled the USE_SYSTEM_PRINTF
and HAVE_VASPRINTF
code paths in g_vasprintf()
.
Signed-off-by: Philip Withnall pwithnall@gnome.org
Fixes: #3187 (closed)
Closes #3187 (closed)