charsets: set error if UTF-8 validation fails

Otherwise, mm_modem_charset_bytearray_to_utf8() may return NULL
without error set, and that will trigger a crash in the caller.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/511
This commit is contained in:
Aleksander Morgado
2022-02-17 09:59:24 +01:00
parent 6aec0a6c80
commit 27f6679aa8
+11 -4
View File
@@ -865,11 +865,18 @@ mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray,
g_assert_not_reached ();
}
if (utf8 && g_utf8_validate (utf8, -1, NULL))
return g_steal_pointer (&utf8);
if (!utf8) {
g_prefix_error (error, "Invalid conversion from %s to UTF-8: ", settings->gsm_name);
return NULL;
}
g_prefix_error (error, "Invalid conversion from %s to UTF-8: ", settings->gsm_name);
return NULL;
if (!g_utf8_validate (utf8, -1, NULL)) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Invalid conversion from %s: invalid UTF-8", settings->gsm_name);
return NULL;
}
return g_steal_pointer (&utf8);
}
gchar *