Skip to content

Commit

Permalink
portal: Remap --env-fd into child process's fd space
Browse files Browse the repository at this point in the history
Just because we can allocate a new, unused fd in the portal's fd space,
that doesn't mean that fd number is going to be unused in the child
process's fd space: we might need to remap it.

Resolves: #4286
Fixes: aeb6a7a "portal: Convert --env in extra-args into --env-fd"
Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv authored and alexlarsson committed May 25, 2021
1 parent a09d07f commit 526dae9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions portal/flatpak-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ handle_spawn (PortalFlatpak *object,

if (env_string->len > 0)
{
FdMapEntry fd_map_entry;
g_auto(GLnxTmpfile) env_tmpf = { 0, };

if (!flatpak_buffer_to_sealed_memfd_or_tmpfile (&env_tmpf, "environ",
Expand All @@ -1103,9 +1104,16 @@ handle_spawn (PortalFlatpak *object,
}

env_fd = glnx_steal_fd (&env_tmpf.fd);
child_setup_data.env_fd = env_fd;

/* Use a fd that hasn't been used yet. We might have to reshuffle
* fd_map_entry.to, a bit later. */
fd_map_entry.from = env_fd;
fd_map_entry.to = ++max_fd;
fd_map_entry.final = fd_map_entry.to;
g_array_append_val (fd_map, fd_map_entry);

g_ptr_array_add (flatpak_argv,
g_strdup_printf ("--env-fd=%d", env_fd));
g_strdup_printf ("--env-fd=%d", fd_map_entry.final));
}

for (i = 0; unset_env != NULL && unset_env[i] != NULL; i++)
Expand Down

0 comments on commit 526dae9

Please sign in to comment.