Possible stack overflow in gspawn on MacOS
gspawn can trigger a stack overflow on MacOS when the file descriptors limit is large.
We noticed this error because glib-compile-resources caused build failures for some developers that had:
- max files (ulimit -n) = 1048576
- stack size (ulimit -s) = 8192
The following sample program, with the above limits, causes a segmentation fault in safe_fdwalk_with_invalid_fds
(line 1556):
#include <glib.h>
#include <glib/gstdio.h>
int main() {
gchar *argv[2] = {"/usr/bin/true", NULL};
gint status = 0;
gboolean res = g_spawn_sync(NULL, argv, NULL, G_SPAWN_DEFAULT,
NULL, NULL, NULL, NULL, &status, NULL);
if (res)
g_printf("g_spawn_sync: child exited with code %d\n", status);
else
g_printf("g_spawn_sync: error\n");
return 0;
}