dhcp: escape control characters in DHCP options

Control characters (DEL (=127) or those below 32) could cause undesired
effects when a client displays or parses DHCP options. Escape them.

(cherry picked from commit 0c10e4f8b6)
This commit is contained in:
Beniamino Galvani 2021-07-26 23:58:23 +02:00
parent 8481470557
commit 5f85f1631b
2 changed files with 8 additions and 2 deletions

View file

@ -694,7 +694,10 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx,
/* https://tools.ietf.org/html/rfc2132#section-8.1 */
v_str = nm_utils_buf_utf8safe_escape((char *) l_data, l_data_len, 0, &to_free);
v_str = nm_utils_buf_utf8safe_escape((char *) l_data,
l_data_len,
NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL,
&to_free);
nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, v_str ?: "");
nm_ip4_config_set_nis_domain(ip4_config, v_str ?: "");

View file

@ -404,7 +404,10 @@ nm_dhcp_option_add_option_utf8safe_escape(GHashTable * options,
gs_free char *to_free = NULL;
const char * escaped;
escaped = nm_utils_buf_utf8safe_escape((char *) data, n_data, 0, &to_free);
escaped = nm_utils_buf_utf8safe_escape((char *) data,
n_data,
NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL,
&to_free);
nm_dhcp_option_add_option(options, addr_family, option, escaped ?: "");
}