keyfile: fix escaping ascii control characters in nm_keyfile_key_encode()

Matters when backslash escaping ascii charaters <= 0xF, to
produce "\\XX" instead of "\\ X". For example tabulator is "\\09".

This also can trigger an nm_assert() failure, when building with
--with-more-asserts=5 (or higher).

(cherry picked from commit 89c89143b5)
This commit is contained in:
Thomas Haller 2017-11-20 15:30:36 +01:00
parent de66655f0a
commit 54dad379f3
2 changed files with 6 additions and 1 deletions

View file

@ -442,7 +442,7 @@ _keyfile_key_encode (const char *name,
&& g_ascii_isxdigit (name[i + 2]))
|| ( ch == ' '
&& name[i + 1] == '\0'))
g_string_append_printf (str, "\\%2X", ch);
g_string_append_printf (str, "\\%02X", ch);
else
g_string_append_c (str, (char) ch);
}

View file

@ -99,6 +99,11 @@ test_encode_key (void)
do_test_encode_key_bijection (kf, " ", "\\20 \\20");
do_test_encode_key_decode_surjection (kf, "f\\20c", "f c");
do_test_encode_key_decode_surjection (kf, "\\20\\20\\20", "\\20 \\20");
do_test_encode_key_bijection (kf, "\t", "\\09");
do_test_encode_key_bijection (kf, "\t=x", "\\09\\3Dx");
do_test_encode_key_bijection (kf, "(nm-openvpn-auth-dialog:10283): GdkPixbuf-DEBUG: \tCopy pixels == false",
"(nm-openvpn-auth-dialog:10283): GdkPixbuf-DEBUG: \\09Copy pixels \\3D\\3D false");
}
/*****************************************************************************/