Skip to content

Commit aeda891

Browse files
authored
ext/phar: refactor clean-up code on Windows for phar_open_parsed_phar() (#21839)
1 parent 20b0ff7 commit aeda891

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

ext/phar/phar.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,20 @@ static zend_result phar_open_parsed_phar(char *fname, size_t fname_len, char *al
504504
phar_unixify_path_separators(fname, fname_len);
505505
}
506506
#endif
507-
if (SUCCESS == phar_get_archive(&phar, fname, fname_len, alias, alias_len, error)
508-
&& ((alias && zend_string_equals_cstr(phar->fname, fname, fname_len)) || !alias)
509-
) {
507+
zend_result archive_retrieved = phar_get_archive(&phar, fname, fname_len, alias, alias_len, error);
508+
/* logic is as follows:
509+
- If no alias was passed in, then it can match either and be valid
510+
- If an explicit alias was requested, ensure the filename passed in matches the phar's filename.
511+
*/
512+
bool process_phar = SUCCESS == archive_retrieved && (!alias || zend_string_equals_cstr(phar->fname, fname, fname_len));
510513
#ifdef PHP_WIN32
511-
if (fname != save_fname) {
512-
free_alloca(fname, fname_use_heap);
513-
fname = save_fname;
514-
}
514+
if (fname != save_fname) {
515+
free_alloca(fname, fname_use_heap);
516+
fname = save_fname;
517+
}
515518
#endif
519+
520+
if (process_phar) {
516521
/* logic above is as follows:
517522
If an explicit alias was requested, ensure the filename passed in
518523
matches the phar's filename.
@@ -537,12 +542,6 @@ static zend_result phar_open_parsed_phar(char *fname, size_t fname_len, char *al
537542

538543
return SUCCESS;
539544
} else {
540-
#ifdef PHP_WIN32
541-
if (fname != save_fname) {
542-
free_alloca(fname, fname_use_heap);
543-
fname = save_fname;
544-
}
545-
#endif
546545
if (pphar) {
547546
*pphar = NULL;
548547
}

0 commit comments

Comments
 (0)