Use *array() allocation functions where appropriate
This prevents overflow from multiplication. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
727275a027
commit
191f04f7dc
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user