[php-src] master: Fix -Walloc-size warning
| From: | Ilija Tovilo | Date: | Mon, 29 Apr 2024 14:43:40 +0000 |
| Subject: | [php-src] master: Fix -Walloc-size warning | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-128252@lists.php.net to get a copy of this message | ||
Author: Ilija Tovilo (iluuu1994)
Date: 2024-04-29T16:36:24+02:00
Commit: https://github.com/php/php-src/commit/782af7a963e66b4da7646b4c84d820fa376d88b0
Raw diff: https://github.com/php/php-src/commit/782af7a963e66b4da7646b4c84d820fa376d88b0.diff
Fix -Walloc-size warning
It's indeed unsafe to treat zend_internal_function as zend_function, because
sizeof(zend_internal_function) < sizeof(zend_function), which can lead to buffer
overflows. This might also be UB.
Either way, this would need to be addressed in the whole codebase.
Changed paths:
M Zend/zend_inheritance.c
Diff:
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index 491d68714b3c..c07415ce8204 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -97,7 +97,7 @@ static zend_function *zend_duplicate_internal_function(zend_function *func, zend
zend_function *new_function;
if (UNEXPECTED(ce->type & ZEND_INTERNAL_CLASS)) {
- new_function = pemalloc(sizeof(zend_internal_function), 1);
+ new_function = (zend_function *)pemalloc(sizeof(zend_internal_function), 1);
memcpy(new_function, func, sizeof(zend_internal_function));
} else {
new_function = zend_arena_alloc(&CG(arena), sizeof(zend_internal_function));