Skip to content

Commit

Permalink
Merge pull request #1587 from aconz2/uidgid-xstrdup
Browse files Browse the repository at this point in the history
linux: copy map_file before tokenizing in uidgidmap_helper
  • Loading branch information
giuseppe authored Oct 25, 2024
2 parents 2381713 + 3647eca commit 135f6aa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2873,17 +2873,18 @@ libcrun_reopen_dev_null (libcrun_error_t *err)
}

static int
uidgidmap_helper (char *helper, pid_t pid, char *map_file, libcrun_error_t *err)
uidgidmap_helper (char *helper, pid_t pid, const char *map_file, libcrun_error_t *err)
{
#define MAX_ARGS 20
char pid_fmt[16];
char *args[MAX_ARGS + 1];
char *next;
cleanup_free char *map_file_copy = xstrdup (map_file);
size_t nargs = 0;
args[nargs++] = helper;
sprintf (pid_fmt, "%d", pid);
args[nargs++] = pid_fmt;
next = map_file;
next = map_file_copy;
while (nargs < MAX_ARGS)
{
char *p = strsep (&next, " \n");
Expand All @@ -2897,13 +2898,13 @@ uidgidmap_helper (char *helper, pid_t pid, char *map_file, libcrun_error_t *err)
}

static int
newgidmap (pid_t pid, char *map_file, libcrun_error_t *err)
newgidmap (pid_t pid, const char *map_file, libcrun_error_t *err)
{
return uidgidmap_helper ("newgidmap", pid, map_file, err);
}

static int
newuidmap (pid_t pid, char *map_file, libcrun_error_t *err)
newuidmap (pid_t pid, const char *map_file, libcrun_error_t *err)
{
return uidgidmap_helper ("newuidmap", pid, map_file, err);
}
Expand Down

0 comments on commit 135f6aa

Please sign in to comment.