Skip to content

Fix out-of-tree configure writing to read-only source tree - #24597

Open
prateekbhujel wants to merge 1 commit into
php:PHP-8.4from
prateekbhujel:fix/configure-readonly-srcdir
Open

prateekbhujel wants to merge 1 commit into
php:PHP-8.4from
prateekbhujel:fix/configure-readonly-srcdir

Conversation

@prateekbhujel

Copy link
Copy Markdown
Contributor

Description

As reported by Mukonda Kangwa on the PHP internals mailing list (https://externals.io/message/132904), running configure out-of-tree against a read-only source tree attempts to write main/php_config.h.in.tmp into $srcdir, fails with a filesystem error, and still exits with status 0.

Specifically, PHP_PATCH_CONFIG_HEADERS in build/php.m4 previously executed:

$SED -e 's/^#undef PACKAGE_[^ ]*/\/\* & \*\//g' < $srcdir/$1 \
  > $srcdir/$1.tmp && mv $srcdir/$1.tmp $srcdir/$1

This causes three problems during out-of-tree builds:

  1. It mutates $srcdir by writing $srcdir/$1.tmp and overwriting $srcdir/$1.
  2. When $srcdir is read-only, the redirection fails (Read-only file system / Permission denied), and because configure does not check the exit status of the pipeline, configure continues and exits 0.
  3. When the write to $srcdir/main/php_config.h.in fails on a fresh source tree or release tarball, config.status falls back to the unpatched $srcdir/main/php_config.h.in and emits #define PACKAGE_* macros into main/php_config.h, defeating the purpose of PHP_PATCH_CONFIG_HEADERS.

Fix

Autoconf's config.status resolves AC_CONFIG_HEADERS input templates in the build tree first (test -f "$ac_f") before falling back to $srcdir/$ac_f.

This change updates PHP_PATCH_CONFIG_HEADERS in build/php.m4 to:

  1. Ensure the target parent directory exists in the build tree via AS_MKDIR_P(["$(AS_DIRNAME(["$1"]))"]) before writing, since AC_CONFIG_COMMANDS_PRE hooks cannot assume the target subdirectory already exists.
  2. Read from "$srcdir/$1" and write "$1.tmp" -> "$1" in the current build directory, leaving $srcdir untouched during out-of-tree builds while preserving in-place behavior for in-tree builds ($srcdir = .).
  3. Fail with AC_MSG_ERROR([failed to patch $1]) if generating or moving the patched header template fails.

Verification

  • Verified in-tree configure and ./config.status execution.
  • Verified out-of-tree configure with a read-only source tree (chmod -R a-w as an unprivileged user): $srcdir remains unmodified, main/php_config.h.in and main/php_config.h are generated in the build tree with /* #undef PACKAGE_* */, and rerunning ./config.status preserves the patched output.
  • Verified error propagation (configure: error: failed to patch ... with exit status 1) when template generation fails.
  • Verified full CLI build (--disable-all --enable-cli --disable-cgi --disable-phpdbg --without-pear) and phpize extension configuration (both in-tree and out-of-tree with a read-only extension source directory).

@cinematografiagranados-cpu

This comment was marked as spam.

PHP_PATCH_CONFIG_HEADERS previously wrote its temporary file and patched
configuration header template directly into $srcdir. During out-of-tree
builds with a read-only source tree, redirecting to $srcdir/$1.tmp
failed with a filesystem error that was ignored, leaving configure to
exit with status 0 while config.status consumed the unpatched template.

Ensure the target directory exists in the build tree, generate the
patched header template in the build directory (which Autoconf's
config.status checks before falling back to $srcdir), and fail with
AC_MSG_ERROR if patching the template fails.

Reported by Mukonda Kangwa on the PHP internals mailing list:
https://externals.io/message/132904
@prateekbhujel
prateekbhujel force-pushed the fix/configure-readonly-srcdir branch from 4d52a71 to c894ed4 Compare October 23, 2026 11:17
@prateekbhujel
prateekbhujel changed the base branch from master to PHP-8.4 October 23, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants