Files
httrack/tests/108_engine-refetch-backup.test
Xavier Roche 90b98e740e A URL can still be saved onto the engine's own temporary files (#853)
* A URL can still be saved onto the engine's own temporary files

The re-fetch backup and the content-coding temporaries built their names
inside the mirror, so a site serving the matching path had its mirrored
copy used as scratch and then deleted. #818 escaped hts-cache and hts-tmp
as reserved path components, but three shapes still got through (#842): a
trailing space that cleanEndingSpaceOrDot() stripped back off after the
check, and the first path component, which the table could not see because
it anchors on a leading '/' that url_savename has already removed. The
latter covers a single-label hostname too, and left the DOS device names
equally exposed in that position.

The temporaries now live in ~hts-tmp/. url_savename maps '~' to '_' in
every name it builds, so nothing a site can serve resolves inside it
whatever the escape does; the escape is still fixed, as defence for
hts-cache/ itself. The frozen-slot spool (<save>.tmp) shared the
collision, plus a heap buffer sized from url_sav that the path_html branch
overran, and moves to the same helper. The .delayed placeholder does not:
it goes through url_savename's collision detection, so a competing link
gets a suffix rather than the file.

Closes #774
Closes #842

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>

* Scope the reserved-name escape and fix the review blockers

Restrict the new first-component match so a hostname label is not rewritten:
only a trailing run cleanEndingSpaceOrDot() strips may end the name there,
so aux.example.com keeps its name while a single-label hts-tmp host and a
path-first hts-cache/ are still escaped. Renaming a host directory would
have moved an existing mirror out from under --update --purge-old.

Drop the frozen-slot spool rewrite: it carried a pre-existing heap overflow
that belongs in its own change. Clear back->tmpfile when structcheck() fails
in the named branch, as the unnamed one does. Test 132 now plants a leftover
at the exact temporary path, so both a reverted HTS_TMPDIR and a no-op
back_refetch_backup fail it; 131 pins the hostname labels.

Signed-off-by: Xavier Roche <roche@httrack.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>

---------

Signed-off-by: Xavier Roche <roche@httrack.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 23:44:15 +02:00

26 lines
738 B
Bash
Executable File

#!/bin/bash
#
# Drives -#test=refetchbackup: the #77 re-fetch backup must leave a copy of the
# resource whatever happens, and must not build its temporary name inside the
# mirror namespace (#774, #775).
set -euo pipefail
dir=$(mktemp -d)
trap 'set +e; rm -rf "$dir"' EXIT
trap 'set +e; rm -rf "$dir"; exit 1' HUP INT QUIT PIPE TERM
rc=0
out=$(httrack -O /dev/null -#test=refetchbackup "$dir" 2>&1) || rc=$?
if test "$rc" -ne 0 || ! grep -q "refetchbackup: OK" <<<"$out"; then
echo "FAIL (exit $rc): $out" >&2
exit 1
fi
# The temporaries live in ~hts-tmp and the last user removes it.
leftovers=$(find "$dir" -mindepth 1 | head -5)
test -z "$leftovers" || {
echo "FAIL: leftover temporaries: $leftovers" >&2
exit 1
}