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

@@ -635,7 +635,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
return 0;
}
entries = malloc (n * sizeof (struct commonio_entry *));
entries = mallocarray (n, sizeof (struct commonio_entry *));
if (entries == NULL) {
return -1;
}

View File

@@ -46,7 +46,7 @@
for (i = 0; grent->gr_mem[i]; i++);
/*@-mustfreeonly@*/
gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
gr->gr_mem = (char **) mallocarray (i + 1, sizeof (char *));
/*@=mustfreeonly@*/
if (NULL == gr->gr_mem) {
gr_free(gr);

View File

@@ -117,7 +117,7 @@ void endsgent (void)
size_t len = strlen (string) + 1;
if (len > sgrbuflen) {
char *buf = (char *) realloc (sgrbuf, sizeof (char) * len);
char *buf = (char *) reallocarray (sgrbuf, len, sizeof (char));
if (NULL == buf) {
return NULL;
}

View File

@@ -44,7 +44,7 @@ static char **list (char *s)
member name, or terminating NULL). */
if (i >= size) {
size = i + 100; /* at least: i + 1 */
members = reallocf (members, size * sizeof (char *));
members = reallocarrayf (members, size, sizeof(char *));
if (!members)
return NULL;
}

View File

@@ -49,7 +49,7 @@
for (i = 0; NULL != sgent->sg_adm[i]; i++);
/*@-mustfreeonly@*/
sg->sg_adm = (char **) malloc ((i + 1) * sizeof (char *));
sg->sg_adm = (char **) mallocarray (i + 1, sizeof (char *));
/*@=mustfreeonly@*/
if (NULL == sg->sg_adm) {
free (sg->sg_passwd);
@@ -74,7 +74,7 @@
for (i = 0; NULL != sgent->sg_mem[i]; i++);
/*@-mustfreeonly@*/
sg->sg_mem = (char **) malloc ((i + 1) * sizeof (char *));
sg->sg_mem = (char **) mallocarray (i + 1, sizeof (char *));
/*@=mustfreeonly@*/
if (NULL == sg->sg_mem) {
for (i = 0; NULL != sg->sg_adm[i]; i++) {

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;