Skip to content

Commit 814300a

Browse files
Mark fatal string allocation overflow as unreachable
Let GCC see that non-fallible overflow handling aborts, avoiding false array-bounds errors in callers that copy into the allocated string.
1 parent c42e75c commit 814300a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎Zend/zend_string.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ static zend_always_inline size_t zend_string_safe_len(size_t n, size_t m, size_t
140140

141141
if (UNEXPECTED(overflow || len > ZSTR_MAX_LEN)) {
142142
zend_mm_delayed_error_or_panic(fallible, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", n, m, l);
143+
if (!fallible) {
144+
/* zend_mm_delayed_error_or_panic() aborts for !fallible, but its body
145+
* is in zend_alloc.c and is not visible when compiling other source files.
146+
* Its declaration cannot use ZEND_NORETURN because the fallible path returns. */
147+
ZEND_UNREACHABLE();
148+
}
143149
return SIZE_MAX;
144150
}
145151
return len;

0 commit comments

Comments
 (0)