Skip to content

Commit 521c0c5

Browse files
committed
Refactor path name processing in phar_build()
1 parent fa15b7e commit 521c0c5

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

ext/phar/phar_object.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,6 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
14111411
goto after_open_fp;
14121412
case IS_OBJECT:
14131413
if (instanceof_function(Z_OBJCE_P(value), spl_ce_SplFileInfo)) {
1414-
char *test = NULL;
14151414
spl_filesystem_object *intern = PHAR_FETCH_INTERNAL_EX(value);
14161415

14171416
if (!base_len) {
@@ -1421,41 +1420,34 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
14211420

14221421
switch (intern->type) {
14231422
case SPL_FS_DIR: {
1423+
char *tmp;
14241424
zend_string *test_str = spl_filesystem_object_get_path(intern);
1425-
fname_len = spprintf(&fname, 0, "%s%c%s", ZSTR_VAL(test_str), DEFAULT_SLASH, intern->u.dir.entry.d_name);
1425+
fname_len = spprintf(&tmp, 0, "%s%c%s", ZSTR_VAL(test_str), DEFAULT_SLASH, intern->u.dir.entry.d_name);
14261426
zend_string_release_ex(test_str, /* persistent */ false);
1427-
if (php_stream_stat_path(fname, &ssb) == 0 && S_ISDIR(ssb.sb.st_mode)) {
1427+
if (php_stream_stat_path(tmp, &ssb) == 0 && S_ISDIR(ssb.sb.st_mode)) {
14281428
/* ignore directories */
1429-
efree(fname);
1429+
efree(tmp);
14301430
return ZEND_HASH_APPLY_KEEP;
14311431
}
14321432

1433-
test = expand_filepath(fname, NULL);
1434-
efree(fname);
1435-
1436-
if (test) {
1437-
fname = test;
1438-
fname_len = strlen(fname);
1439-
} else {
1440-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Could not resolve file path");
1441-
return ZEND_HASH_APPLY_STOP;
1442-
}
1443-
1444-
save = fname;
1445-
goto phar_spl_fileinfo;
1433+
fname = expand_filepath(tmp, NULL);
1434+
efree(tmp);
1435+
break;
14461436
}
14471437
case SPL_FS_INFO:
14481438
case SPL_FS_FILE:
14491439
fname = expand_filepath(ZSTR_VAL(intern->file_name), NULL);
1450-
if (!fname) {
1451-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Could not resolve file path");
1452-
return ZEND_HASH_APPLY_STOP;
1453-
}
1440+
break;
1441+
}
14541442

1455-
fname_len = strlen(fname);
1456-
save = fname;
1457-
goto phar_spl_fileinfo;
1443+
if (!fname) {
1444+
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Could not resolve file path");
1445+
return ZEND_HASH_APPLY_STOP;
14581446
}
1447+
1448+
fname_len = strlen(fname);
1449+
save = fname;
1450+
goto phar_spl_fileinfo;
14591451
}
14601452
ZEND_FALLTHROUGH;
14611453
default:

0 commit comments

Comments
 (0)