Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77eaa43

Browse files
Fix concat_function use-after-free on out-of-memory error
Introduced by phpGH-10049
1 parent c230aa9 commit 77eaa43

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

‎Zend/zend_operators.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,11 +2048,6 @@ has_op2_string:;
20482048
}
20492049

20502050
if (result == op1) {
2051-
if (free_op1_string) {
2052-
/* op1_string will be used as the result, so we should not free it */
2053-
i_zval_ptr_dtor(result);
2054-
free_op1_string = false;
2055-
}
20562051
/* special case, perform operations on result */
20572052
result_str = zend_string_extend(op1_string, result_len, 0);
20582053
/* account for the case where result_str == op1_string == op2_string and the realloc is done */
@@ -2063,6 +2058,14 @@ has_op2_string:;
20632058
}
20642059
op2_string = result_str;
20652060
}
2061+
/* Free result last, as zend_string_extend() may throw an out-of-memory error. If we free
2062+
* it before we would leave the released variable on the stack with shutdown trying to
2063+
* freeing it again. */
2064+
if (free_op1_string) {
2065+
/* op1_string will be used as the result, so we should not free it */
2066+
i_zval_ptr_dtor(result);
2067+
free_op1_string = false;
2068+
}
20662069
} else {
20672070
result_str = zend_string_alloc(result_len, 0);
20682071
memcpy(ZSTR_VAL(result_str), ZSTR_VAL(op1_string), op1_len);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /