]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
create_run_template: don't use txtuid and txtguid out of scope 4487/head
authorSerge Hallyn <serge@hallyn.com>
Thu, 10 Oct 2024 04:18:42 +0000 (23:18 -0500)
committerSerge Hallyn <serge@hallyn.com>
Sun, 13 Oct 2024 15:11:12 +0000 (10:11 -0500)
It's ok that we don't free the malloc()d space since we're
immediately exec()ing.

Originally-by: Kurt Godwin <kgodwin@itron.com>
Reported-by: Kurt Godwin <kgodwin@itron.com>
Signed-off-by: Serge Hallyn <serge@hallyn.com>
src/lxc/lxccontainer.c

index 41b62201b659766b7e9cc22dc639cb06cedd20ac..0d71cfad80a827ae52c401841e87b150bf3260b2 100644 (file)
@@ -1455,7 +1455,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath,
                if (!list_empty(&conf->id_map)) {
                        int extraargs, hostuid_mapped, hostgid_mapped;
                        char **n2;
-                       char txtuid[20], txtgid[20];
+                       char *txtuid = NULL, *txtgid = NULL;
                        struct id_map *map;
                        int n2args = 1;
 
@@ -1556,6 +1556,12 @@ static bool create_run_template(struct lxc_container *c, char *tpath,
                        /* note n2[n2args-1] is NULL */
                        n2[n2args - 5] = "--mapped-uid";
 
+                       txtuid = malloc(20);
+                       if (!txtuid) {
+                               free(newargv);
+                               free(n2);
+                               _exit(EXIT_FAILURE);
+                       }
                        ret = strnprintf(txtuid, 20, "%d", hostuid_mapped);
                        if (ret < 0) {
                                free(newargv);
@@ -1566,6 +1572,12 @@ static bool create_run_template(struct lxc_container *c, char *tpath,
                        n2[n2args - 4] = txtuid;
                        n2[n2args - 3] = "--mapped-gid";
 
+                       txtgid = malloc(20);
+                       if (!txtgid) {
+                               free(newargv);
+                               free(n2);
+                               _exit(EXIT_FAILURE);
+                       }
                        ret = strnprintf(txtgid, 20, "%d", hostgid_mapped);
                        if (ret < 0) {
                                free(newargv);