]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: free grp to avoid leak 291/head
authorikerexxe <ipedrosa@redhat.com>
Tue, 27 Oct 2020 10:35:53 +0000 (11:35 +0100)
committerikerexxe <ipedrosa@redhat.com>
Tue, 27 Oct 2020 10:42:34 +0000 (11:42 +0100)
covscan issue:
Error: RESOURCE_LEAK (CWE-772): [#def39] [important]
src/useradd.c:728: alloc_fn: Storage is returned from allocation function "get_local_group".
src/useradd.c:728: var_assign: Assigning: "grp" = storage returned from "get_local_group(list)".
src/useradd.c:728: overwrite_var: Overwriting "grp" in "grp = get_local_group(list)" leaks the storage that "grp" points to.
726|     * GID values, otherwise the string is looked up as is.
727|     */
728|->  grp = get_local_group (list);
729|
730|    /*

src/useradd.c

index 3544acd01161ccaf1b53f088a619560c426e2121..107e65f8503d9404a639c0d3822a15e075a96d45 100644 (file)
@@ -729,7 +729,7 @@ static int set_defaults (void)
 static int get_groups (char *list)
 {
        char *cp;
-       const struct group *grp;
+       struct group *grp;
        int errors = 0;
        int ngroups = 0;
 
@@ -808,6 +808,7 @@ static int get_groups (char *list)
                 * Add the group name to the user's list of groups.
                 */
                user_groups[ngroups++] = xstrdup (grp->gr_name);
+               free (grp);
        } while (NULL != list);
 
        close_group_files ();