gresolver: Convert encoding of gai_strerror() return value

It returns a string in the libc locale, which is not necessarily UTF-8.
Convert that to UTF-8 before returning it to the caller.

Spotted by Tomasz Miąsko.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1732
This commit is contained in:
Philip Withnall
2019-03-22 13:30:43 +00:00
parent abeac84105
commit 89416debb0
2 changed files with 9 additions and 11 deletions

View File

@@ -343,15 +343,14 @@ handle_ip_address (const char *hostname,
#ifdef G_OS_WIN32
gchar *error_message = g_win32_error_message (WSAHOST_NOT_FOUND);
#else
const gchar *error_message = gai_strerror (EAI_NONAME);
gchar *error_message = g_locale_to_utf8 (gai_strerror (EAI_NONAME), -1, NULL, NULL, NULL);
if (error_message == NULL)
error_message = g_strdup ("[Invalid UTF-8]");
#endif
g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND,
_("Error resolving “%s”: %s"),
hostname, error_message);
#ifdef G_OS_WIN32
g_free (error_message);
#endif
return TRUE;
}