[php-src] PR #24597: Fix out-of-tree configure writing to read-only source tree
| From: | prateekbhujel | Date: | Fri, 23 Oct 2026 10:45:34 +0000 |
| Subject: | [php-src] PR #24597: Fix out-of-tree configure writing to read-only source tree | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39761@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24597
Author: prateekbhujel
### 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:
```m4
$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).