diff options
author | Ronan Pigott <ronan@rjp.ie> | 2024-01-23 21:12:30 +0100 |
---|---|---|
committer | Ronan Pigott <ronan@rjp.ie> | 2024-10-21 18:10:19 +0200 |
commit | 1be9b30a3b1768cac1e5010574e265aca86d8f11 (patch) | |
tree | 3d0a4cae448974d50e1de86bb3b69dbc461822b0 /src/libsystemd-network | |
parent | test-dhcp6: terminate fqdn option (diff) | |
download | systemd-1be9b30a3b1768cac1e5010574e265aca86d8f11.tar.xz systemd-1be9b30a3b1768cac1e5010574e265aca86d8f11.zip |
dhcp6: use dns_name_from_wire_format
Convert some of the option parsing to use dns_name_from_wire_format,
introduced earlier. No change in behavior intended.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/dhcp6-option.c | 76 | ||||
-rw-r--r-- | src/libsystemd-network/test-dhcp6-client.c | 5 |
2 files changed, 5 insertions, 76 deletions
diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c index 83f40f3f02..787cc37d00 100644 --- a/src/libsystemd-network/dhcp6-option.c +++ b/src/libsystemd-network/dhcp6-option.c @@ -820,74 +820,6 @@ int dhcp6_option_parse_addresses( return 0; } -static int parse_domain(const uint8_t **data, size_t *len, char **ret) { - _cleanup_free_ char *domain = NULL; - const uint8_t *optval; - size_t optlen, n = 0; - int r; - - assert(data); - assert(len); - assert(*data || *len == 0); - assert(ret); - - optval = *data; - optlen = *len; - - if (optlen <= 1) - return -ENODATA; - - for (;;) { - const char *label; - uint8_t c; - - if (optlen == 0) - break; - - c = *optval; - optval++; - optlen--; - - if (c == 0) - /* End label */ - break; - if (c > 63) - return -EBADMSG; - if (c > optlen) - return -EMSGSIZE; - - /* Literal label */ - label = (const char*) optval; - optval += c; - optlen -= c; - - if (!GREEDY_REALLOC(domain, n + (n != 0) + DNS_LABEL_ESCAPED_MAX)) - return -ENOMEM; - - if (n != 0) - domain[n++] = '.'; - - r = dns_label_escape(label, c, domain + n, DNS_LABEL_ESCAPED_MAX); - if (r < 0) - return r; - - n += r; - } - - if (n > 0) { - if (!GREEDY_REALLOC(domain, n + 1)) - return -ENOMEM; - - domain[n] = '\0'; - } - - *ret = TAKE_PTR(domain); - *data = optval; - *len = optlen; - - return n; -} - int dhcp6_option_parse_domainname(const uint8_t *optval, size_t optlen, char **ret) { _cleanup_free_ char *domain = NULL; int r; @@ -895,7 +827,7 @@ int dhcp6_option_parse_domainname(const uint8_t *optval, size_t optlen, char **r assert(optval || optlen == 0); assert(ret); - r = parse_domain(&optval, &optlen, &domain); + r = dns_name_from_wire_format(&optval, &optlen, &domain); if (r < 0) return r; if (r == 0) @@ -922,11 +854,11 @@ int dhcp6_option_parse_domainname_list(const uint8_t *optval, size_t optlen, cha while (optlen > 0) { _cleanup_free_ char *name = NULL; - r = parse_domain(&optval, &optlen, &name); + r = dns_name_from_wire_format(&optval, &optlen, &name); if (r < 0) return r; - if (r == 0) - continue; + if (dns_name_is_root(name)) /* root domain */ + return -EBADMSG; r = strv_consume(&names, TAKE_PTR(name)); if (r < 0) diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index 8c89365140..882c04afbb 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -165,10 +165,7 @@ TEST(parse_domain) { domain = mfree(domain); data = (uint8_t []) { 4, 't', 'e', 's', 't' }; - assert_se(dhcp6_option_parse_domainname(data, 5, &domain) >= 0); - assert_se(domain); - assert_se(streq(domain, "test")); - domain = mfree(domain); + assert_se(dhcp6_option_parse_domainname(data, 5, &domain) < 0); data = (uint8_t []) { 0 }; assert_se(dhcp6_option_parse_domainname(data, 1, &domain) < 0); |