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
@@ -834,7 +834,7 @@ static void get_group (struct group *gr)
|
||||
|
||||
sg->sg_mem = dup_list (gr->gr_mem);
|
||||
|
||||
sg->sg_adm = (char **) xmalloc (sizeof (char *) * 2);
|
||||
sg->sg_adm = (char **) xmallocarray (2, sizeof (char *));
|
||||
#ifdef FIRST_MEMBER_IS_ADMIN
|
||||
if (sg->sg_mem[0]) {
|
||||
sg->sg_adm[0] = xstrdup (sg->sg_mem[0]);
|
||||
|
||||
@@ -88,7 +88,7 @@ int main (int argc, char **argv)
|
||||
GETGROUPS_T *groups;
|
||||
|
||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||
groups = (GETGROUPS_T *) malloc (sizeof (GETGROUPS_T) * sys_ngroups);
|
||||
groups = (GETGROUPS_T *) mallocarray (sys_ngroups, sizeof (GETGROUPS_T));
|
||||
|
||||
(void) setlocale (LC_ALL, "");
|
||||
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
|
||||
2
src/id.c
2
src/id.c
@@ -63,7 +63,7 @@ static void usage (void)
|
||||
* work if the system library is recompiled.
|
||||
*/
|
||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||
groups = (GETGROUPS_T *) malloc (sizeof (GETGROUPS_T) * sys_ngroups);
|
||||
groups = (GETGROUPS_T *) mallocarray (sys_ngroups, sizeof (GETGROUPS_T));
|
||||
|
||||
/*
|
||||
* See if the -a flag has been given to print out the concurrent
|
||||
|
||||
@@ -531,7 +531,7 @@ int main (int argc, char **argv)
|
||||
/* don't use getgroups(0, 0) - it doesn't work on some systems */
|
||||
i = 16;
|
||||
for (;;) {
|
||||
grouplist = (GETGROUPS_T *) xmalloc (i * sizeof (GETGROUPS_T));
|
||||
grouplist = (GETGROUPS_T *) xmallocarray (i, sizeof (GETGROUPS_T));
|
||||
ngroups = getgroups (i, grouplist);
|
||||
if (i > ngroups && !(ngroups == -1 && errno == EINVAL)) {
|
||||
break;
|
||||
|
||||
@@ -1200,9 +1200,9 @@ int main (int argc, char **argv)
|
||||
#ifdef USE_PAM
|
||||
/* keep the list of user/password for later update by PAM */
|
||||
nusers++;
|
||||
lines = reallocf (lines, sizeof (lines[0]) * nusers);
|
||||
usernames = reallocf (usernames, sizeof (usernames[0]) * nusers);
|
||||
passwords = reallocf (passwords, sizeof (passwords[0]) * nusers);
|
||||
lines = reallocf (lines, nusers, sizeof (lines[0]));
|
||||
usernames = reallocf (usernames, nusers, sizeof (usernames[0]));
|
||||
passwords = reallocf (passwords, nusers, sizeof (passwords[0]));
|
||||
if (lines == NULL || usernames == NULL || passwords == NULL) {
|
||||
fprintf (stderr,
|
||||
_("%s: line %d: %s\n"),
|
||||
|
||||
2
src/su.c
2
src/su.c
@@ -238,7 +238,7 @@ static void execve_shell (const char *shellname,
|
||||
while (NULL != args[n_args]) {
|
||||
n_args++;
|
||||
}
|
||||
targs = (char **) xmalloc ((n_args + 3) * sizeof (args[0]));
|
||||
targs = (char **) xmallocarray (n_args + 3, sizeof (args[0]));
|
||||
targs[0] = "sh";
|
||||
targs[1] = "-";
|
||||
targs[2] = xstrdup (shellname);
|
||||
|
||||
@@ -2539,7 +2539,7 @@ int main (int argc, char **argv)
|
||||
#endif
|
||||
|
||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||
user_groups = (char **) xmalloc ((1 + sys_ngroups) * sizeof (char *));
|
||||
user_groups = (char **) xmallocarray (1 + sys_ngroups, sizeof (char *));
|
||||
/*
|
||||
* Initialize the list to be empty
|
||||
*/
|
||||
|
||||
@@ -2150,7 +2150,7 @@ int main (int argc, char **argv)
|
||||
#endif
|
||||
|
||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||
user_groups = (char **) malloc (sizeof (char *) * (1 + sys_ngroups));
|
||||
user_groups = (char **) mallocarray (sys_ngroups + 1, sizeof (char *));
|
||||
user_groups[0] = NULL;
|
||||
|
||||
is_shadow_pwd = spw_file_present ();
|
||||
|
||||
Reference in New Issue
Block a user