mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
gspawn: Fix use of uninitialised FDs on error path
Spotted by scan-build, an actual true positive result from it, and a fiendish one too. If any of the calls to `dupfd_cloexec()` (except the final one) fail, the remainder of the `duped_source_fds` array would have been left uninitialised. The code in `out_close_fds` would have then called `g_clear_fd()` on an uninitialised FD, with unpredictable results. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #1767
This commit is contained in:
parent
3c6c60611f
commit
96552fc904
@ -1811,6 +1811,8 @@ do_posix_spawn (const gchar * const *argv,
|
||||
goto out_close_fds;
|
||||
|
||||
duped_source_fds = g_new (gint, n_fds);
|
||||
for (i = 0; i < n_fds; i++)
|
||||
duped_source_fds[i] = -1; /* initialise in case dupfd_cloexec() fails below */
|
||||
for (i = 0; i < n_fds; i++)
|
||||
{
|
||||
duped_source_fds[i] = dupfd_cloexec (source_fds[i], max_target_fd + 1);
|
||||
|
Loading…
Reference in New Issue
Block a user