Skip to content

Commit ee4bfb4

Browse files
committed
Fix GH-17797: zend_test_compile_string crash on invalid script path.
When looking for the last slash of the script path, it leads to underflow being promoted to SIZE_MAX being way beyond MAXPATHLEN.
1 parent a54af45 commit ee4bfb4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

main/fopen_wrappers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
603603
const char *exec_fname = ZSTR_VAL(exec_filename);
604604
size_t exec_fname_length = ZSTR_LEN(exec_filename);
605605

606-
while ((--exec_fname_length < SIZE_MAX) && !IS_SLASH(exec_fname[exec_fname_length]));
606+
do {
607+
if (exec_fname_length == 0) break;
608+
} while (!IS_SLASH(exec_fname[--exec_fname_length]));
607609
if (exec_fname_length > 0 &&
608610
filename_length < (MAXPATHLEN - 2) &&
609611
exec_fname_length + 1 + filename_length + 1 < MAXPATHLEN) {

0 commit comments

Comments
 (0)