summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-10-01 15:48:13 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-10-02 23:05:05 +0900
commit60cbf2ea8228e3d2b7dd06fe6ad25dbf09339fef (patch)
tree75fa911fc80d3eb4c41fa912e7d5026bd1fd503f /src/libsystemd-network
parent451daa394e6d256c33599794559454e765243b4e (diff)
downloadsystemd-60cbf2ea8228e3d2b7dd06fe6ad25dbf09339fef.tar.gz
sd-dhcp6-client: use GREEDY_REALLOC()
And merge 'total' and 'offset' -> 'n'
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp6-option.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c
index f257c56681..f0a6b53a42 100644
--- a/src/libsystemd-network/dhcp6-option.c
+++ b/src/libsystemd-network/dhcp6-option.c
@@ -396,7 +396,7 @@ int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) {
int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class) {
_cleanup_free_ uint8_t *p = NULL;
- size_t total = 0, offset = 0;
+ size_t n = 0;
assert(buf);
assert(*buf);
@@ -407,24 +407,19 @@ int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *
STRV_FOREACH(s, user_class) {
size_t len = strlen(*s);
- uint8_t *q;
- if (len > 0xffff || len == 0)
+ if (len > UINT16_MAX || len == 0)
return -EINVAL;
- q = realloc(p, total + len + 2);
- if (!q)
- return -ENOMEM;
-
- p = q;
- unaligned_write_be16(&p[offset], len);
- memcpy(&p[offset + 2], *s, len);
+ if (!GREEDY_REALLOC(p, n + len + 2))
+ return -ENOMEM;
- offset += 2 + len;
- total += 2 + len;
+ unaligned_write_be16(p + n, len);
+ memcpy(p + n + 2, *s, len);
+ n += len + 2;
}
- return dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_USER_CLASS, total, p);
+ return dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_USER_CLASS, n, p);
}
int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *vendor_class) {