mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-12 09:17:44 +03:00
Merge pull request #23260 from yuwata/libsystemd-network-raw-size
libsystemd-network: two fixlets
This commit is contained in:
commit
080b8c2ace
@ -116,6 +116,9 @@ sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n) {
|
||||
sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size) {
|
||||
sd_lldp_neighbor *n;
|
||||
|
||||
if (raw_size > SIZE_MAX - ALIGN(sizeof(sd_lldp_neighbor)))
|
||||
return NULL;
|
||||
|
||||
n = malloc0(ALIGN(sizeof(sd_lldp_neighbor)) + raw_size);
|
||||
if (!n)
|
||||
return NULL;
|
||||
@ -649,7 +652,8 @@ int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw, size_t ra
|
||||
if (!n)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(LLDP_NEIGHBOR_RAW(n), raw, raw_size);
|
||||
memcpy_safe(LLDP_NEIGHBOR_RAW(n), raw, raw_size);
|
||||
|
||||
r = lldp_neighbor_parse(n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -21,6 +21,9 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_ndisc_router, sd_ndisc_router, mfree);
|
||||
sd_ndisc_router *ndisc_router_new(size_t raw_size) {
|
||||
sd_ndisc_router *rt;
|
||||
|
||||
if (raw_size > SIZE_MAX - ALIGN(sizeof(sd_ndisc_router)))
|
||||
return NULL;
|
||||
|
||||
rt = malloc0(ALIGN(sizeof(sd_ndisc_router)) + raw_size);
|
||||
if (!rt)
|
||||
return NULL;
|
||||
@ -31,27 +34,6 @@ sd_ndisc_router *ndisc_router_new(size_t raw_size) {
|
||||
return rt;
|
||||
}
|
||||
|
||||
int sd_ndisc_router_from_raw(sd_ndisc_router **ret, const void *raw, size_t raw_size) {
|
||||
_cleanup_(sd_ndisc_router_unrefp) sd_ndisc_router *rt = NULL;
|
||||
int r;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(raw || raw_size <= 0, -EINVAL);
|
||||
|
||||
rt = ndisc_router_new(raw_size);
|
||||
if (!rt)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(NDISC_ROUTER_RAW(rt), raw, raw_size);
|
||||
r = ndisc_router_parse(NULL, rt);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret = TAKE_PTR(rt);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int sd_ndisc_router_get_address(sd_ndisc_router *rt, struct in6_addr *ret_addr) {
|
||||
assert_return(rt, -EINVAL);
|
||||
assert_return(ret_addr, -EINVAL);
|
||||
|
@ -82,7 +82,6 @@ int sd_ndisc_set_ifname(sd_ndisc *nd, const char *interface_name);
|
||||
int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret);
|
||||
int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr);
|
||||
|
||||
int sd_ndisc_router_from_raw(sd_ndisc_router **ret, const void *raw, size_t raw_size);
|
||||
sd_ndisc_router *sd_ndisc_router_ref(sd_ndisc_router *rt);
|
||||
sd_ndisc_router *sd_ndisc_router_unref(sd_ndisc_router *rt);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user