supplicant: don't put binary data in error message for supplicant

For better or worse, the API does not require the value to be a
UTF-8 string. We cannot just concatenate binary to a string.
Instead, backslash escape it with utf8safe-escape.

Also, this will shut up a (wrong) coverity warning at this place.

(cherry picked from commit 55143dad95)
This commit is contained in:
Thomas Haller 2019-08-02 17:34:59 +02:00
parent d99925a1b0
commit da933ffe2a

View file

@ -139,11 +139,17 @@ nm_supplicant_config_add_option_with_type (NMSupplicantConfig *self,
else {
type = nm_supplicant_settings_verify_setting (key, value, len);
if (type == TYPE_INVALID) {
char buf[255];
memset (&buf[0], 0, sizeof (buf));
memcpy (&buf[0], value, len > 254 ? 254 : len);
gs_free char *str_free = NULL;
const char *str;
str = nm_utils_buf_utf8safe_escape (value, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &str_free);
str = nm_strquote_a (255, str);
g_set_error (error, NM_SUPPLICANT_ERROR, NM_SUPPLICANT_ERROR_CONFIG,
"key '%s' and/or value '%s' invalid", key, hidden ?: buf);
"key '%s' and/or value %s invalid",
key,
hidden ?: str);
return FALSE;
}
}