dhclient: allow single hex digits in hexadecimal dhcp_client_id
When checking whether the dhcp-client-identifier is a hex string, we expected pairs of hexadecimal digits separated by colon. Relax this check to also allow single hex digits. https://bugzilla.gnome.org/show_bug.cgi?id=737727 Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -74,16 +74,24 @@ add_hostname (GString *str, const char *format, const char *hostname)
|
||||
static void
|
||||
add_ip4_config (GString *str, const char *dhcp_client_id, const char *hostname)
|
||||
{
|
||||
if (dhcp_client_id) {
|
||||
if (dhcp_client_id && *dhcp_client_id) {
|
||||
gboolean is_octets = TRUE;
|
||||
int i = 0;
|
||||
|
||||
while (dhcp_client_id[i]) {
|
||||
if ((i % 3) != 2 && !g_ascii_isxdigit (dhcp_client_id[i])) {
|
||||
if (!g_ascii_isxdigit (dhcp_client_id[i])) {
|
||||
is_octets = FALSE;
|
||||
break;
|
||||
}
|
||||
if ((i % 3) == 2 && dhcp_client_id[i] != ':') {
|
||||
i++;
|
||||
if (!dhcp_client_id[i])
|
||||
break;
|
||||
if (g_ascii_isxdigit (dhcp_client_id[i])) {
|
||||
i++;
|
||||
if (!dhcp_client_id[i])
|
||||
break;
|
||||
}
|
||||
if (dhcp_client_id[i] != ':') {
|
||||
is_octets = FALSE;
|
||||
break;
|
||||
}
|
||||
|
@@ -180,6 +180,34 @@ test_ascii_client_id (void)
|
||||
|
||||
/*******************************************/
|
||||
|
||||
static const char *hex_single_client_id_expected = \
|
||||
"# Created by NetworkManager\n"
|
||||
"\n"
|
||||
"send dhcp-client-identifier ab:cd:e:12:34:56; # added by NetworkManager\n"
|
||||
"\n"
|
||||
"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
|
||||
"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
|
||||
"option wpad code 252 = string;\n"
|
||||
"\n"
|
||||
"also request rfc3442-classless-static-routes;\n"
|
||||
"also request ms-classless-static-routes;\n"
|
||||
"also request static-routes;\n"
|
||||
"also request wpad;\n"
|
||||
"also request ntp-servers;\n"
|
||||
"\n";
|
||||
|
||||
static void
|
||||
test_hex_single_client_id (void)
|
||||
{
|
||||
test_config (NULL, hex_single_client_id_expected,
|
||||
NULL,
|
||||
"ab:cd:e:12:34:56",
|
||||
"eth0",
|
||||
NULL);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
|
||||
static const char *override_hostname_orig = \
|
||||
"send host-name \"foobar\";\n";
|
||||
|
||||
@@ -586,6 +614,7 @@ main (int argc, char **argv)
|
||||
g_test_add_func ("/dhcp/dhclient/override_client_id", test_override_client_id);
|
||||
g_test_add_func ("/dhcp/dhclient/quote_client_id", test_quote_client_id);
|
||||
g_test_add_func ("/dhcp/dhclient/ascii_client_id", test_ascii_client_id);
|
||||
g_test_add_func ("/dhcp/dhclient/hex_single_client_id", test_hex_single_client_id);
|
||||
g_test_add_func ("/dhcp/dhclient/override_hostname", test_override_hostname);
|
||||
g_test_add_func ("/dhcp/dhclient/existing_alsoreq", test_existing_alsoreq);
|
||||
g_test_add_func ("/dhcp/dhclient/existing_multiline_alsoreq", test_existing_multiline_alsoreq);
|
||||
|
Reference in New Issue
Block a user