Skip to content

Commit 742c940

Browse files
committed
Download PIE to a temp directory before verifying
1 parent 93bdfd1 commit 742c940

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ AS_VAR_IF([PHP_CLI], [no], [with_pie=no])
11941194
PHP_ARG_WITH([pie],
11951195
[whether to install PIE],
11961196
[AS_HELP_STRING([[--with-pie[=DIR]]],
1197-
[Install PIE in DIR [PREFIX/lib/php]])],
1197+
[Install PIE in DIR [PREFIX/bin]])],
11981198
[no],
11991199
[yes])
12001200

pie/Makefile.frag

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,44 @@ PIE_PHP_FLAGS = -dmemory_limit=-1
55
CURL = `which curl 2>/dev/null`
66
WGET = `which wget 2>/dev/null`
77
FETCH = `which fetch 2>/dev/null`
8+
FETCH_PHP = $(top_srcdir)/pear/fetch.php
89
GH = `which gh 2>/dev/null`
910
PIE_PHAR_URL = https://github.com/php/pie/releases/latest/download/pie.phar
10-
11+
PIE_PHAR_TEMP_DL_LOCATION = $(top_srcdir)/pie/pie_temp.phar
1112
PIE_PHAR_DESTINATION = $(INSTALL_ROOT)$(piedir)/pie
1213

1314
$(PIE_PHAR_DESTINATION):
1415
@echo "Installing PIE: $(PIE_PHAR_DESTINATION)"
16+
# First, figure out a way to download the phar, with curl, wget, fetch, or a backup PHP script...
1517
@if test ! -z "$(CURL)" && test -x "$(CURL)"; then \
16-
"$(CURL)" --no-progress-meter --silent --location "${PIE_PHAR_URL}" --output $(PIE_PHAR_DESTINATION); \
18+
echo " downloading ${PIE_PHAR_URL} with ${CURL} to ${PIE_PHAR_TEMP_DL_LOCATION}"; \
19+
"$(CURL)" --no-progress-meter --silent --location "${PIE_PHAR_URL}" --output $(PIE_PHAR_TEMP_DL_LOCATION); \
1720
elif test ! -z "$(WGET)" && test -x "$(WGET)"; then \
18-
"$(WGET)" "${PIE_PHAR_URL}" --quiet --no-directories --output-document=$(PIE_PHAR_DESTINATION); \
21+
echo " downloading ${PIE_PHAR_URL} with ${WGET} to ${PIE_PHAR_TEMP_DL_LOCATION}"; \
22+
"$(WGET)" "${PIE_PHAR_URL}" --quiet --no-directories --output-document=$(PIE_PHAR_TEMP_DL_LOCATION); \
1923
elif test ! -z "$(FETCH)" && test -x "$(FETCH)"; then \
20-
"$(FETCH)" -o $(PIE_PHAR_DESTINATION) "${PIE_PHAR_URL}"; \
24+
echo " downloading ${PIE_PHAR_URL} with ${FETCH} to ${PIE_PHAR_TEMP_DL_LOCATION}"; \
25+
"$(FETCH)" -o $(PIE_PHAR_TEMP_DL_LOCATION) "${PIE_PHAR_URL}"; \
2126
else \
22-
$(top_builddir)/sapi/cli/php -n $(top_srcdir)/pear/fetch.php "${PIE_PHAR_URL}" $(PIE_PHAR_DESTINATION) ; \
27+
echo " downloading ${PIE_PHAR_URL} with ${FETCH_PHP} to ${PIE_PHAR_TEMP_DL_LOCATION}"; \
28+
$(top_builddir)/sapi/cli/php -n "${FETCH_PHP}" "${PIE_PHAR_URL}" $(PIE_PHAR_TEMP_DL_LOCATION) ; \
2329
fi
30+
# Try to verify using `gh` CLI, or if not use `self-verify` (which isn't the best, since it could already have been tampered)
2431
@if test ! -z "$(GH)" && test -x "$(GH)"; then \
25-
"$(GH)" attestation verify --owner=php $(PIE_PHAR_DESTINATION); \
32+
echo " verifying ${PIE_PHAR_TEMP_DL_LOCATION} with ${GH}"; \
33+
"$(GH)" attestation verify --owner=php $(PIE_PHAR_TEMP_DL_LOCATION); \
2634
else \
27-
$(top_builddir)/sapi/cli/php $(PIE_PHP_FLAGS) $(PIE_PHAR_DESTINATION) self-verify; \
35+
echo " verifying ${PIE_PHAR_TEMP_DL_LOCATION} with self-verify (insecure)"; \
36+
$(top_builddir)/sapi/cli/php $(PIE_PHP_FLAGS) $(PIE_PHAR_TEMP_DL_LOCATION) self-verify; \
2837
fi
38+
# Once verified, move it to the real location
39+
@echo " move ${PIE_PHAR_TEMP_DL_LOCATION} to ${PIE_PHAR_DESTINATION}"
40+
@mv $(PIE_PHAR_TEMP_DL_LOCATION) $(PIE_PHAR_DESTINATION)
2941
@chmod +x $(PIE_PHAR_DESTINATION)
3042

3143
.PHONY: install-pie
3244
install-pie: $(PIE_PHAR_DESTINATION)
45+
@echo " self-updating ${PIE_PHAR_DESTINATION}"
3346
@$(top_builddir)/sapi/cli/php $(PIE_PHP_FLAGS) $(PIE_PHAR_DESTINATION) self-update > /dev/null 2>&1
47+
@echo " checking version ${PIE_PHAR_DESTINATION}"
3448
@$(top_builddir)/sapi/cli/php $(PIE_PHP_FLAGS) $(PIE_PHAR_DESTINATION) --version

pie/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
When building PHP, supply the `--with-pie` flag. This will attempt to download
44
the latest stable version of PIE, using `curl`, `wget`, `fetch`, or a PHP script.
55

6-
By default it will download PIE to `$prefix/lib/php/pie`. You can change
6+
By default it will download PIE to `$prefix/bin/pie`. You can change
77
the target path, e.g. `--with-pie=/usr/local/bin`, which will cause PIE to be
88
downloaded to `/usr/local/bin/pie`.
99

0 commit comments

Comments
 (0)