From edd718ba48b6e6e6ce7f34290c39ad74bbf743bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 6 Jul 2022 23:54:14 +0200 Subject: [PATCH] gstrfuncs: Handle the case strerror_r returns an error In the case strerror_r returns an error (both in the char* variant and in the int variant) we should not try to proceed converting the message and adding to the errors maps, as that's likely causing errors. So, let's just return a null string in case this happens --- glib/gstrfuncs.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 21ec0b578..7522cfa6e 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -1336,6 +1336,9 @@ g_strerror (gint errnum) { gchar buf[1024]; GError *error = NULL; +#if defined(HAVE_STRERROR_R) && !defined(STRERROR_R_CHAR_P) + int ret; +#endif #if defined(G_OS_WIN32) strerror_s (buf, sizeof (buf), errnum); @@ -1345,13 +1348,23 @@ g_strerror (gint errnum) # if defined(STRERROR_R_CHAR_P) msg = strerror_r (errnum, buf, sizeof (buf)); # else - (void) strerror_r (errnum, buf, sizeof (buf)); - msg = buf; + ret = strerror_r (errnum, buf, sizeof (buf)); + if (ret == 0 || ret == EINVAL) + msg = buf; # endif /* HAVE_STRERROR_R */ #else g_strlcpy (buf, strerror (errnum), sizeof (buf)); msg = buf; #endif + + if (!msg) + { + G_UNLOCK (errors); + + errno = saved_errno; + return msg; + } + if (!g_get_console_charset (NULL)) { msg = g_locale_to_utf8 (msg, -1, NULL, NULL, &error);