Skip to content

Commit 2d0cec1

Browse files
committed
Another review round
1 parent a694243 commit 2d0cec1

File tree

1 file changed

+27
-54
lines changed

1 file changed

+27
-54
lines changed

ext/phar/phar_object.c

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -710,17 +710,16 @@ PHP_METHOD(Phar, webPhar)
710710
return;
711711
default:
712712
zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false");
713-
goto cleanup_fail;
714-
}
715713

716714
cleanup_fail:
717-
zval_ptr_dtor(&params);
718-
if (free_pathinfo) {
719-
efree(path_info);
715+
zval_ptr_dtor(&params);
716+
if (free_pathinfo) {
717+
efree(path_info);
718+
}
719+
efree(entry);
720+
efree(pt);
721+
RETURN_THROWS();
720722
}
721-
efree(entry);
722-
efree(pt);
723-
RETURN_THROWS();
724723
}
725724

726725
if (entry_len) {
@@ -2840,27 +2839,26 @@ PHP_METHOD(Phar, setStub)
28402839
zend_long len = -1;
28412840
php_stream *stream;
28422841

2843-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "r|l", &zstub, &len) == SUCCESS) {
2842+
PHAR_ARCHIVE_OBJECT();
28442843

2845-
PHAR_ARCHIVE_OBJECT();
2844+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
2845+
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2846+
"Cannot change stub, phar is read-only");
2847+
RETURN_THROWS();
2848+
}
28462849

2847-
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
2850+
if (phar_obj->archive->is_data) {
2851+
if (phar_obj->archive->is_tar) {
28482852
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2849-
"Cannot change stub, phar is read-only");
2850-
RETURN_THROWS();
2851-
}
2852-
2853-
if (phar_obj->archive->is_data) {
2854-
if (phar_obj->archive->is_tar) {
2855-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2856-
"A Phar stub cannot be set in a plain tar archive");
2857-
} else {
2858-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2859-
"A Phar stub cannot be set in a plain zip archive");
2860-
}
2861-
RETURN_THROWS();
2853+
"A Phar stub cannot be set in a plain tar archive");
2854+
} else {
2855+
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2856+
"A Phar stub cannot be set in a plain zip archive");
28622857
}
2858+
RETURN_THROWS();
2859+
}
28632860

2861+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "r|l", &zstub, &len) == SUCCESS) {
28642862
if ((php_stream_from_zval_no_verify(stream, zstub)) != NULL) {
28652863
if (len > 0) {
28662864
len = -len;
@@ -2882,26 +2880,6 @@ PHP_METHOD(Phar, setStub)
28822880
"Cannot change stub, unable to read from input stream");
28832881
}
28842882
} else if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &stub, &stub_len) == SUCCESS) {
2885-
2886-
PHAR_ARCHIVE_OBJECT();
2887-
2888-
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
2889-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2890-
"Cannot change stub, phar is read-only");
2891-
RETURN_THROWS();
2892-
}
2893-
2894-
if (phar_obj->archive->is_data) {
2895-
if (phar_obj->archive->is_tar) {
2896-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2897-
"A Phar stub cannot be set in a plain tar archive");
2898-
} else {
2899-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
2900-
"A Phar stub cannot be set in a plain zip archive");
2901-
}
2902-
RETURN_THROWS();
2903-
}
2904-
29052883
if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
29062884
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
29072885
RETURN_THROWS();
@@ -3752,13 +3730,13 @@ PHP_METHOD(Phar, offsetUnset)
37523730
size_t fname_len;
37533731
phar_entry_info *entry;
37543732

3733+
PHAR_ARCHIVE_OBJECT();
3734+
37553735
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
37563736
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly");
37573737
RETURN_THROWS();
37583738
}
37593739

3760-
PHAR_ARCHIVE_OBJECT();
3761-
37623740
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
37633741
RETURN_THROWS();
37643742
}
@@ -4322,14 +4300,13 @@ PHP_METHOD(Phar, extractTo)
43224300
int ret;
43234301
zval *zval_file;
43244302
HashTable *files_ht = NULL;
4325-
zend_string *files_str = NULL;
43264303
zend_bool overwrite = 0;
43274304
char *error = NULL;
43284305

43294306
ZEND_PARSE_PARAMETERS_START(1, 3)
43304307
Z_PARAM_PATH(pathto, pathto_len)
4331-
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(files_str, files_ht)
4332-
Z_PARAM_bool(overwrite)
4308+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(filename, files_ht)
4309+
Z_PARAM_BOOL(overwrite)
43334310
ZEND_PARSE_PARAMETERS_END();
43344311

43354312
PHAR_ARCHIVE_OBJECT();
@@ -4371,9 +4348,7 @@ PHP_METHOD(Phar, extractTo)
43714348
RETURN_THROWS();
43724349
}
43734350

4374-
if (files_str) {
4375-
filename = files_str;
4376-
} else if (files_ht) {
4351+
if (files_ht) {
43774352
if (zend_hash_num_elements(files_ht) == 0) {
43784353
RETURN_FALSE;
43794354
}
@@ -4399,8 +4374,6 @@ PHP_METHOD(Phar, extractTo)
43994374
}
44004375
} ZEND_HASH_FOREACH_END();
44014376
RETURN_TRUE;
4402-
} else {
4403-
filename = NULL;
44044377
}
44054378

44064379
ret = extract_helper(phar_obj->archive, filename, pathto, pathto_len, overwrite, &error);

0 commit comments

Comments
 (0)