Skip to content

Commit 8e897f8

Browse files
committed
phar: Avoid the use of goto in Phar::setAlias()
1 parent 0dd2da1 commit 8e897f8

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

ext/phar/phar_object.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,18 +2730,15 @@ PHP_METHOD(Phar, setAlias)
27302730
RETURN_TRUE;
27312731
}
27322732
if (NULL != (fd_ptr = zend_hash_find_ptr(&(PHAR_G(phar_alias_map)), new_alias))) {
2733-
if (SUCCESS == phar_free_alias(fd_ptr, ZSTR_VAL(new_alias), ZSTR_LEN(new_alias))) {
2734-
goto valid_alias;
2733+
if (SUCCESS != phar_free_alias(fd_ptr, ZSTR_VAL(new_alias), ZSTR_LEN(new_alias))) {
2734+
zend_throw_exception_ex(phar_ce_PharException, 0, "alias \"%s\" is already used for archive \"%s\" and cannot be used for other archives", ZSTR_VAL(new_alias), fd_ptr->fname);
2735+
RETURN_THROWS();
27352736
}
2736-
zend_throw_exception_ex(phar_ce_PharException, 0, "alias \"%s\" is already used for archive \"%s\" and cannot be used for other archives", ZSTR_VAL(new_alias), fd_ptr->fname);
2737-
RETURN_THROWS();
2738-
}
2739-
if (!phar_validate_alias(ZSTR_VAL(new_alias), ZSTR_LEN(new_alias))) {
2737+
} else if (!phar_validate_alias(ZSTR_VAL(new_alias), ZSTR_LEN(new_alias))) {
27402738
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
27412739
"Invalid alias \"%s\" specified for phar \"%s\"", ZSTR_VAL(new_alias), phar_obj->archive->fname);
27422740
RETURN_THROWS();
27432741
}
2744-
valid_alias:
27452742
if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
27462743
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
27472744
RETURN_THROWS();

0 commit comments

Comments
 (0)