Use *array() allocation functions where appropriate

This prevents overflow from multiplication.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-02-04 21:47:01 +01:00
committed by Serge Hallyn
parent 727275a027
commit 191f04f7dc
18 changed files with 26 additions and 26 deletions

View File

@@ -319,7 +319,7 @@ static bool append_range(struct subid_range **ranges, const struct subordinate_r
return false;
} else {
struct subid_range *alloced;
alloced = realloc(*ranges, (n + 1) * (sizeof(struct subid_range)));
alloced = reallocarray(*ranges, n + 1, sizeof(struct subid_range));
if (!alloced)
return false;
*ranges = alloced;
@@ -911,7 +911,7 @@ static int append_uids(uid_t **uids, const char *owner, int n)
return n;
}
ret = realloc(*uids, (n + 1) * sizeof(uid_t));
ret = reallocarray(*uids, n + 1, sizeof(uid_t));
if (!ret) {
free(*uids);
return -1;