1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-23 02:04:32 +03:00

resolved: use saturate_add()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-05-12 16:37:10 +02:00
parent 8b0c43475a
commit 14b71de4e1

View File

@ -60,10 +60,7 @@ static int dns_answer_reserve_internal(DnsAnswer *a, size_t n) {
m = ordered_set_size(a->items);
assert(m <= UINT16_MAX); /* We can only place 64K RRs in an answer at max */
if (n > UINT16_MAX - m)
n = UINT16_MAX;
else
n += m;
n = saturate_add(m, n, UINT16_MAX);
/* Higher multipliers give slightly higher efficiency through hash collisions, but the gains
* quickly drop off after 2. */
@ -707,10 +704,7 @@ int dns_answer_reserve_or_clone(DnsAnswer **a, size_t n_free) {
ns = dns_answer_size(*a);
assert(ns <= UINT16_MAX); /* Maximum number of RRs we can stick into a DNS packet section */
if (n_free > UINT16_MAX - ns) /* overflow check */
ns = UINT16_MAX;
else
ns += n_free;
ns = saturate_add(ns, n_free, UINT16_MAX);
n = dns_answer_new(ns);
if (!n)