Skip to content

Commit 8ce99bc

Browse files
arshidkv12bukka
authored andcommitted
Fix GH-21720: macOS posix_spawn_file_actions_addchdir availability handling
On Apple, select the addchdir variant by deployment target instead of the configure check: the link check passes whenever the SDK exports the symbol even if the running system is older, leaving a weakly linked reference that resolves to NULL at runtime and crashing proc_open() when $cwd is used. Closes GH-21722
1 parent 1fd15d4 commit 8ce99bc

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

ext/standard/proc_open.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@
4242
* to be really buggy.
4343
*/
4444
#include <spawn.h>
45+
#ifdef __APPLE__
46+
#include <AvailabilityMacros.h>
47+
#endif
4548
#define USE_POSIX_SPAWN
4649

47-
/* The non-_np variant is in macOS 26 (and _np deprecated) */
48-
#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
50+
/* The non-_np variant is in macOS 26 (and _np deprecated). On Apple, it has to be selected by the
51+
* deployment target rather than the configure check: the link check passes whenever the SDK
52+
* exports the symbol even if the running system is older, in which case the weakly linked
53+
* reference resolves to NULL at runtime. */
54+
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000
55+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir
56+
#elif defined(__APPLE__)
57+
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir_np
58+
#elif defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)
4959
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir
5060
#else
5161
#define POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR posix_spawn_file_actions_addchdir_np

0 commit comments

Comments
 (0)