summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-10-01 15:53:33 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-10-02 23:05:05 +0900
commitcb9c303d70a30853898a2833634949ad35e9fa41 (patch)
tree48b80683cc812ce4f833965b5f33df7685e17d45 /src/libsystemd-network
parent60cbf2ea8228e3d2b7dd06fe6ad25dbf09339fef (diff)
downloadsystemd-cb9c303d70a30853898a2833634949ad35e9fa41.tar.gz
sd-dhcp6-client: use GREEDY_REALLOC() in dhcp6_option_append_vendor_class()
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp6-option.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c
index f0a6b53a42..d258c9aafa 100644
--- a/src/libsystemd-network/dhcp6-option.c
+++ b/src/libsystemd-network/dhcp6-option.c
@@ -424,8 +424,7 @@ int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *
int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *vendor_class) {
_cleanup_free_ uint8_t *p = NULL;
- uint32_t enterprise_identifier;
- size_t total, offset;
+ size_t n = 0;
assert(buf);
assert(*buf);
@@ -434,36 +433,28 @@ int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const
if (strv_isempty(vendor_class))
return 0;
- enterprise_identifier = htobe32(SYSTEMD_PEN);
-
- p = memdup(&enterprise_identifier, sizeof(enterprise_identifier));
- if (!p)
+ if (!GREEDY_REALLOC(p, sizeof(be32_t)))
return -ENOMEM;
- total = sizeof(enterprise_identifier);
- offset = total;
+ /* Enterprise Identifier */
+ unaligned_write_be32(p, SYSTEMD_PEN);
+ n += sizeof(be32_t);
STRV_FOREACH(s, vendor_class) {
size_t len = strlen(*s);
- uint8_t *q;
if (len > UINT16_MAX || len == 0)
return -EINVAL;
- q = realloc(p, total + len + 2);
- if (!q)
+ if (!GREEDY_REALLOC(p, n + len + 2))
return -ENOMEM;
- p = q;
-
- unaligned_write_be16(&p[offset], len);
- memcpy(&p[offset + 2], *s, len);
-
- 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_VENDOR_CLASS, total, p);
+ return dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_VENDOR_CLASS, n, p);
}
int dhcp6_option_parse(