mirror of
https://github.com/xroche/httrack.git
synced 2026-07-28 19:43:02 +03:00
* ARC cache replays a truncated HTTP reason phrase proxytrack bounded the reason-phrase copy out of an ARC index by sizeof(pos) - 1 where pos is a const char *, so a stored "404 Not Found" replays as "404 Not Fou" (and "404 Not" on 32-bit). Use strncatbuff with the destination's own size. Fold the nine copies of the buff() family's source-capacity expression into HTS_SIZEOF_SRC_, applying sizeof to the type so a decayed operand no longer trips -Wsizeof-array-decay at five call sites; MSVC keeps the old expression behind the guard HTS_IS_CHAR_BUFFER already uses. The two other raw strncat calls become strncatbuff, htsbuff_catn stops handing strnlen the (size_t)-1 sentinel, and htsweb.c no longer compares ep against a NULL eps. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com> * Size the new strsafe buffers away from sizeof(char*) char[8] equals a pointer on LP64, so MSVC's array-vs-pointer heuristic read the unterminated source as a pointer, skipped the bound and never aborted; the x64 build failed while Win32 passed. Same trap the existing comment in that function already warns about. 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>
65 lines
2.1 KiB
Bash
Executable File
65 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
# htssafe.h bounded string operations (driven by 'httrack -#test=strsafe').
|
|
|
|
# Success path: every bounded op (strcpybuff/strcatbuff/strncatbuff/strlcpybuff)
|
|
# must behave correctly. 'run' selects the success path (vs the overflow modes).
|
|
rc=0
|
|
out=$(httrack -#test=strsafe run) || rc=$?
|
|
test "$rc" -eq 0 || exit 1
|
|
test "$out" == "strsafe: OK" || exit 1
|
|
|
|
# Overflow path: an over-capacity write into a sized buffer must be caught by
|
|
# the bounded macro and abort the process, not be silently truncated/completed.
|
|
# Assert the htssafe abort signature specifically, so the test cannot pass for
|
|
# an unrelated reason (e.g. the strsafe test being gone, which prints the
|
|
# registry to stderr and also exits non-zero).
|
|
# the bounded macro aborts (non-zero exit), so don't let set -e trip on it
|
|
err=$(httrack -#test=strsafe overflow "this string is far too long for the buffer" 2>&1) || true
|
|
case "$err" in
|
|
*"strsafe: NOT aborted"*)
|
|
echo "over-capacity write was NOT caught" >&2
|
|
exit 1
|
|
;;
|
|
*"overflow while copying"*) ;;
|
|
*)
|
|
echo "expected htssafe overflow abort, got: $err" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Same guarantee for the htsbuff builder. The source is exactly the buffer
|
|
# capacity (6 bytes into a 6-byte buffer), so this also pins the boundary: a
|
|
# '<=' off-by-one in the capacity check would let it through (and print "NOT
|
|
# aborted"). Match the specific htsbuff abort message, not just any assert.
|
|
err=$(httrack -#test=strsafe overflow-buff "abcdef" 2>&1) || true
|
|
case "$err" in
|
|
*"strsafe: NOT aborted"*)
|
|
echo "htsbuff over-capacity write was NOT caught" >&2
|
|
exit 1
|
|
;;
|
|
*"htsbuff append overflow"*) ;;
|
|
*)
|
|
echo "expected htsbuff overflow abort, got: $err" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# An array source with no NUL must abort on the source bound rather than run
|
|
# off the array: the array half of the source-capacity selection.
|
|
err=$(httrack -#test=strsafe overflow-src "x" 2>&1) || true
|
|
case "$err" in
|
|
*"strsafe: NOT aborted"*)
|
|
echo "unterminated source array was NOT caught" >&2
|
|
exit 1
|
|
;;
|
|
*"size < sizeof_source"*) ;;
|
|
*)
|
|
echo "expected htssafe source-bound abort, got: $err" >&2
|
|
exit 1
|
|
;;
|
|
esac
|