Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

zend_set_local_var() overwrites existing compiled variable (CV) zval without calling zval_ptr_dtor()

未關閉 適合新手
#24,668 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@lazerg 已經在處理了。

開始於 2026年10月25日。

  • #24670 來自 @lazerg —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
c, php
領域
backend

研究方向

閱讀 Zend/zend_execute_API.c,比較 zend_set_local_var() 中編譯變數分支與 zend_set_local_var_str() 以及符號表分支。檢查替換前如何釋放既有的 zval 值,接著執行與區域變數指派和參照計數相關的測試。當替換一個已有值的編譯變數時,其先前的值會被釋放,且現有行為不受影響,即為完成。

由索引模型根據 Issue 內容生成。

描述

Bug Status: Needs Triage
Description

In Zend/zend_execute_API.c (lines 1927–1959), when zend_set_local_var(zend_string *name, zval *value, bool force) finds a matching compiled variable (EX_VAR_NUM(str - op_array->vars)), it overwrites *var directly via ZVAL_COPY_VALUE(var, value) without calling zval_ptr_dtor(var) first:

				do {
					if (ZSTR_H(*str) == h &&
					    zend_string_equal_content(*str, name)) {
						zval *var = EX_VAR_NUM(str - op_array->vars);
						ZVAL_COPY_VALUE(var, value);
						return SUCCESS;
					}
					str++;
				} while (str != end);

Compare this with zend_set_local_var_str() immediately below it in Zend/zend_execute_API.c (lines 1978–1987):

				do {
					if (ZSTR_H(*str) == h &&
					    zend_string_equals_cstr(*str, name, len)) {
						zval *var = EX_VAR_NUM(str - op_array->vars);
						zval_ptr_dtor(var);
						ZVAL_COPY_VALUE(var, value);
						return SUCCESS;
					}
					str++;
				} while (str != end);

And in the EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE branch of zend_set_local_var() (line 1954), zend_hash_update_ind(execute_data->symbol_table, name, value) is called, which properly invokes the destructor on the old value. Only the CV branch of zend_set_local_var() (line 1940) omits zval_ptr_dtor(var);, leaking the previous reference-counted value if the CV was already populated.

Suggested Patch
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -1937,6 +1937,7 @@ ZEND_API zend_result zend_set_local_var(zend_string *name, zval *value, bool for
 					if (ZSTR_H(*str) == h &&
 					    zend_string_equal_content(*str, name)) {
 						zval *var = EX_VAR_NUM(str - op_array->vars);
+						zval_ptr_dtor(var);
 						ZVAL_COPY_VALUE(var, value);
 						return SUCCESS;
 					}
PHP Version
PHP 8.4, PHP 8.5, master
Operating System

All

主要語言
C
星號
40.7k
分支
8.3k
平均合併
2 天 20 小時
30 天內合併 PR
147

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。