gspawn: Error out early if a target FD is invalid

Rather than passing it to `dup2()`, which scan-build thinks could cause
problems (I would have thought `dup2()` would just return `EBADF`, but
perhaps some implementations are buggy?).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-10-21 13:13:08 +01:00
parent afdf386580
commit f1eeef3777

View File

@@ -923,7 +923,8 @@ do_exec (gint child_err_report_fd,
child_err_report_fd = new_child_err_report_fd;
}
if (safe_dup2 (source_fds[i], target_fds[i]) < 0)
if (target_fds[i] < 0 ||
safe_dup2 (source_fds[i], target_fds[i]) < 0)
write_err_and_exit (child_err_report_fd, CHILD_DUPFD_FAILED);
g_clear_fd (&source_fds[i], NULL);