Skip to content

Commit

Permalink
create_run_template: don't use txtuid and txtguid out of scope
Browse files Browse the repository at this point in the history
It's ok that we don't free the malloc()d space since we're
immediately exec()ing.

Originally-by: Kurt Godwin <[email protected]>
Reported-by: Kurt Godwin <[email protected]>
Signed-off-by: Serge Hallyn <[email protected]>
  • Loading branch information
hallyn committed Oct 10, 2024
1 parent 5714ae4 commit b60205e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lxc/lxccontainer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 (!txtgid) {
free(newargv);
free(n2);
_exit(EXIT_FAILURE);
}
ret = strnprintf(txtuid, 20, "%d", hostuid_mapped);
if (ret < 0) {
free(newargv);
Expand All @@ -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);
Expand Down

0 comments on commit b60205e

Please sign in to comment.