FPM/FastCGI: FCGI_HASH_FUNC reads var[3] for 3-character names (guarded only by var_len < 3)
維護者通常 1 天內回覆
評估
研究方向
閱讀main/fastcgi.h中的FCGI_HASH_FUNC定義,以及main/fastcgi.c中第1019行附近的FastCGI參數解析呼叫。檢查雜湊函式如何處理長度為三個字元的名稱,接著檢視現有的FastCGI測試,找出適合涵蓋此情況的位置。當雜湊不再讀取超出三個字元名稱的範圍,且相關測試通過時,工作即告完成。
由索引模型根據 Issue 內容生成。
描述
Description
main/fastcgi.h:
#define FCGI_HASH_FUNC(var, var_len) \
(UNEXPECTED(var_len < 3) ? (unsigned int)var_len : \
(((unsigned int)var[3]) << 2) + \
(((unsigned int)var[var_len-2]) << 4) + \
(((unsigned int)var[var_len-1]) << 2) + \
var_len)
The guard is var_len < 3, but the body reads var[3]. For a name of length exactly 3, the valid indices are 0..2, so var[3] is one byte past the name.
In FastCGI param parsing (main/fastcgi.c:1019) name and value are contiguous in the param buffer:
fcgi_hash_set(&req->env, FCGI_HASH_FUNC(p, name_len), (char*)p, name_len, (char*)p + name_len, val_len);
so for a 3-char name var[3] reads the first byte of the value (or the record terminator) — inside the allocation. A true 1-byte out-of-bounds read is only conceivable for a crafted record whose 3-char name sits exactly at the end of the content buffer with an empty value; even then the byte is only fed into a hash and never returned, and the whole surface is behind the FastCGI socket.
So this is a minor correctness nit / optional hardening, not a security issue. Confirmed by source on PHP-8.6 and PHP-8.3 (main/fastcgi.h).
Suggested fix
Guard the var[3] access — e.g. change the condition to var_len < 4 so that 3-char names take the (unsigned int)var_len fast path. This only changes internal hash values (recomputed each run) and removes the past-the-name read.
PHP Version
PHP-8.6 and PHP-8.3 branch heads (confirmed by source).
Operating System
Linux
- 主要語言
- C
- 星號
- 41.9k
- 分支
- 8.5k
- 平均合併
- 2 天 16 小時
- 30 天內合併 PR
- 117
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
php/php-src 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
FPM: fpm_request_end() releases the scoreboard writer lock without acquiring it (8.6 regression)未關閉
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
Bug Status: Verified
難度 1/5 1 小時以內 新手友好度 74/100
維護者通常 1 天內回覆
-
getimagesize(): WebP VP8 dimensions are accepted with an invalid start code可能已有人在做 @lazerg 於 5 天前認領。 未關閉Bug Status: Needs Triage
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
相似的 Issue
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBuffer未關閉
難度 2/5 1-3 小時 新手友好度 78/100
-
needs triage
難度 2/5 1-3 小時 新手友好度 72/100
389ds/389-ds-base#8251 ·
維護者通常 1 天內回覆
-
bug data-types
難度 2/5 1-3 小時 新手友好度 76/100
ClickHouse/clickhouse-cpp#645 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
ROCm/hrx-system#3628 ·
維護者通常 1 天內回覆