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
+2
-2
@@ -46,7 +46,7 @@ int add_groups (const char *list)
|
||||
|
||||
i = 16;
|
||||
for (;;) {
|
||||
grouplist = (gid_t *) malloc (i * sizeof (GETGROUPS_T));
|
||||
grouplist = (gid_t *) mallocarray (i, sizeof (GETGROUPS_T));
|
||||
if (NULL == grouplist) {
|
||||
return -1;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ int add_groups (const char *list)
|
||||
fputs (_("Warning: too many groups\n"), shadow_logfd);
|
||||
break;
|
||||
}
|
||||
tmp = (gid_t *) realloc (grouplist, (size_t)(ngroups + 1) * sizeof (GETGROUPS_T));
|
||||
tmp = (gid_t *) reallocarray (grouplist, (size_t)ngroups + 1, sizeof (GETGROUPS_T));
|
||||
if (NULL == tmp) {
|
||||
free (grouplist);
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user