[php-src] Issue #23704: Missing NULL check on zend_hash_index_find() return value in extract_token_id_to_replace() (ext/tokenizer/tokenizer.c)

From: Date: Wed, 16 Sep 2026 10:14:54 +0000
Subject: [php-src] Issue #23704: Missing NULL check on zend_hash_index_find() return value in extract_token_id_to_replace() (ext/tokenizer/tokenizer.c)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252743@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/23704 Author: ushevchenko ### Description This is not a reproducible runtime bug in the classic sense — I have not found a PHP-level call path that currently triggers a crash. It's a defensive-check gap found via static analysis (Svace checker DEREF_OF_NULL.RET.STAT, a statistical checker: 85 of 86 other call sites of zend_hash_index_find() in this codebase check the result for NULL before dereferencing it; this one doesn't). Code in question (ext/tokenizer/tokenizer.c, extract_token_id_to_replace()): ​```c if (Z_TYPE_P(token_zv) == IS_ARRAY) { id_zv = zend_hash_index_find(Z_ARRVAL_P(token_zv), 0); text_zv = zend_hash_index_find(Z_ARRVAL_P(token_zv), 1); } else if (Z_TYPE_P(token_zv) == IS_OBJECT) { id_zv = OBJ_PROP_NUM(Z_OBJ_P(token_zv), 0); text_zv = OBJ_PROP_NUM(Z_OBJ_P(token_zv), 1); } else { return NULL; } ZEND_ASSERT(Z_TYPE_P(text_zv) == IS_STRING); ​``` If token_zv is an array missing index 1, zend_hash_index_find() returns NULL for text_zv, which is then dereferenced via Z_TYPE_P()/Z_STRLEN_P()/Z_STRVAL_P() without a check — ZEND_ASSERT provides no protection in release (NDEBUG) builds. If this path is known to be unreachable in practice, feel free to close as not-a-bug — otherwise a defensive NULL check would be a small low-risk fix, consistent with how this function already returns NULL for other malformed-input cases. ### PHP Version ```plain PHP 8.3.24 (ALT php8.3 package, snapshot 8.3.24-alt1); also confirmed present in the current upstream master branch. ``` ### Operating System Not OS-specific source-level defect

« previous php.bugs (#252743) next »