mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 21:00:07 +01:00
agent: print error message character in hex form if it's unprintable
Currently, when the agent manager is sent a registration request containing UTF-8 characters, it will form an invalid error message using only one of the bytes from the UTF-8 sequence, which causes an assertion in glib to fail, which replaces the returned error message with "[Invalid UTF-8]". It will also print an assertion failure to the console, or crash NetworkManager on non-release builds. This commit makes it so that it instead prints out the character in hexadecimal form if it isn't normally printable, so that it is once again a valid UTF-8 string. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1965 Fixes:a30cf19858('agent: add agent manager and minimal agent class') (cherry picked from commitc9327b2e8b) (cherry picked from commitf6f466ccf8)
This commit is contained in:
parent
277863ef8f
commit
19a8feaad6
1 changed files with 8 additions and 2 deletions
|
|
@ -327,11 +327,17 @@ validate_identifier(const char *identifier, GError **error)
|
|||
/* FIXME: do complete validation here */
|
||||
while (p && *p) {
|
||||
if (!g_ascii_isalnum(*p) && (*p != '_') && (*p != '-') && (*p != '.')) {
|
||||
char invalid_char[5] = {*p};
|
||||
|
||||
if (!g_ascii_isprint(*p)) {
|
||||
g_snprintf(invalid_char, sizeof(invalid_char), "\\x%02x", *p);
|
||||
}
|
||||
|
||||
g_set_error(error,
|
||||
NM_AGENT_MANAGER_ERROR,
|
||||
NM_AGENT_MANAGER_ERROR_INVALID_IDENTIFIER,
|
||||
"Identifier contains invalid character '%c'",
|
||||
*p);
|
||||
"Identifier contains invalid character '%s'",
|
||||
invalid_char);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue