Files
FTL/patch/civetweb.sh
DL6ER 7064780cfb Take CivetWeb from our own fork instead of upstream master
The sources are now copied from https://github.com/DL6ER/civetweb (branch
`pi-hole`), which is CivetWeb master plus the fixes we have pending upstream.
That branch stays deliberately close to master - only necessary and security
fixes go on it, everything Pi-hole specific stays in `patch/civetweb/`.

This picks up two memory-safety fixes we were missing: the integer underflow in
the multipart form field length, where `next` can point before `hend` on a
malformed part and the unchecked pointer subtraction underflows `size_t`, and
the endless loop on a truncated URL-encoded body. Neither is upstream yet, so
waiting for a CivetWeb release would not have given us either. It also brings
the error status for custom error pages, which we need for the static web
interface.

`patch/civetweb.sh` now applies the stack with `git apply --3way` rather than
`patch`. This is not cosmetic: `patch` matches hunks by surrounding context and
silently applies them elsewhere when that context has drifted. Dropping our
sources in and running the old script applied three patches into the wrong place
while still reporting success, so `mg_request_info.csrf_token`, the
`mg_server_port.addr` union and the thread `setpriority()` call all vanished and
the tree no longer compiled. A three-way merge uses the blob a patch was
generated against and either merges correctly or leaves a real conflict, and it
copes with code moving around - which is the normal case after a bump. The
script also fails now instead of printing that everything applied okay.

The Kepler patch had lost the leading space on three of its context lines, which
GNU `patch` tolerates and `git apply` rejects; those are restored.

The PROXY protocol v2 patch is dropped: it is on the fork as a commit, so
carrying it here as well conflicts.

Signed-off-by: DL6ER <dl6er@dl6er.de>
2026-08-01 14:26:13 +02:00

47 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
# Re-apply the Pi-hole modifications on top of a fresh CivetWeb drop.
#
# The sources are copied in by hand from a checkout of
# https://github.com/DL6ER/civetweb (branch `pi-hole`), which tracks CivetWeb
# master plus the fixes we have pending upstream. Everything Pi-hole specific
# lives here rather than on that branch, so it stays close to master.
#
# We use `git apply --3way` rather than `patch`. `patch` matches hunks by
# surrounding context and, when that context has drifted, silently applies them
# somewhere else: three of these patches were quietly lost that way while
# `patch` still reported success. A three-way merge uses the blob the patch was
# generated against, so it either merges correctly or leaves a real conflict.
# It also tolerates code moving around, which is the normal case after a bump.
#
# The drop has to be committed (or at least staged) before running this, since
# the three-way merge needs the index to hold the unpatched sources.
set -e
fail=0
for patch in \
0001-add-pihole-mods.patch \
0001-Always-Kepler-syntax-for-Lua-server-pages.patch \
0001-Add-FTL-URI-rewriting-changes-to-CivetWeb.patch \
0001-Register-CSRF-token-in-conn-request_info.patch \
0001-Log-debug-messages-to-webserver.log-when-debug.webse.patch \
0001-Expose-bound-to-addresses-from-CivetWeb-to-the-front.patch \
0001-Increase-niceness-of-all-civetweb-threads-as-DNS-ope.patch \
0001-Demote-server-side-TLS-handshake-alerts-to-debug.patch
do
printf 'Applying %s ... ' "$patch"
if git apply --3way --index "patch/civetweb/$patch"; then
echo "ok"
else
echo "FAILED"
fail=1
fi
done
if [ "$fail" -ne 0 ]; then
echo "One or more patches did not apply - resolve the conflicts before building." >&2
exit 1
fi
echo "ALL PATCHES APPLIED OKAY"