NULL pointer derefs on g_vasprintf() failure
There are multiple places in GLib where we dereference the string pointer produced by g_vasprintf() without guarding against a NULL result.
This seems dangerous since *s*printf() functions can fail when the %lc and %ls conversions are used. Depending on the locale, there may be no multibyte representation for the passed-in character, causing this function to fail with errno set to EILSEQ. This will cause vasprintf() to return -1 to g_vasprintf(), which handles this by returning a NULL string to the caller. If at compile time defined(HAVE_GOOD_PRINTF) && !defined(HAVE_VASPRINTF), g_vasprintf() will probably crash instead of returning.
This affects at least g_print() and g_printerr(). See e.g: https://gitlab.gnome.org/GNOME/glib/blob/c46565d56a94d960109ff819f13d5c4f3bba721d/glib/gmessages.c#L3176
Here's a code snippet demonstrating the issue:
#include <glib.h>
#include <locale.h>
int
main (int argc, char *argv [])
{
setlocale (LC_ALL, "C"); /* Works with en_US.utf-8 */
g_print ("%lc\n", 0x23ba);
return 0;
}
I can go over the printf() use in GLib and produce a patch for all the instances of the issue I find. We'd need to decide what to do in g_print() where the printf() call fails -- do we print something like an "[Invalid format]" placeholder, or nothing at all? @pwithnall, what do you think?