summaryrefslogtreecommitdiff
path: root/ext/zip/php_zip.c
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2020-03-05 15:26:26 +0100
committerRemi Collet <remi@php.net>2020-03-06 10:27:29 +0100
commitbe14d4e135832988b21736af8de71369fa652620 (patch)
tree4c58ef979ecc80dd2733047868ff7937714179e1 /ext/zip/php_zip.c
parentf3c24ec26520e886c41227a6dbc5f4f27827bc52 (diff)
downloadphp-git-be14d4e135832988b21736af8de71369fa652620.tar.gz
better fix for #72374
Diffstat (limited to 'ext/zip/php_zip.c')
-rw-r--r--ext/zip/php_zip.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index c167ceedc2..8986279602 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -1644,7 +1644,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
{
zval *self = ZEND_THIS;
char *path = ".";
- char *remove_path = NULL, *save_remove_path;
+ char *remove_path = NULL;
char *add_path = NULL;
size_t add_path_len, remove_path_len = 0, path_len = 1;
zend_long remove_all_path = 0;
@@ -1676,15 +1676,6 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
RETURN_FALSE;
}
- save_remove_path = remove_path;
- if (remove_path && remove_path_len > 1) {
- size_t real_len = strlen(remove_path);
- if ((real_len > 1) && ((remove_path[real_len - 1] == '/') || (remove_path[real_len - 1] == '\\'))) {
- remove_path = estrndup(remove_path, real_len - 1);
- remove_path_len -= 1;
- }
- }
-
if (type == 1) {
found = php_zip_glob(ZSTR_VAL(pattern), ZSTR_LEN(pattern), glob_flags, return_value);
} else {
@@ -1707,8 +1698,13 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
file_stripped = ZSTR_VAL(basename);
file_stripped_len = ZSTR_LEN(basename);
} else if (remove_path && strstr(Z_STRVAL_P(zval_file), remove_path) != NULL) {
- file_stripped = Z_STRVAL_P(zval_file) + remove_path_len;
- file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len;
+ if (IS_SLASH(Z_STRVAL_P(zval_file)[remove_path_len])) {
+ file_stripped = Z_STRVAL_P(zval_file) + remove_path_len + 1;
+ file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len - 1;
+ } else {
+ file_stripped = Z_STRVAL_P(zval_file) + remove_path_len;
+ file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len;
+ }
} else {
file_stripped = Z_STRVAL_P(zval_file);
file_stripped_len = Z_STRLEN_P(zval_file);
@@ -1741,9 +1737,6 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
}
}
}
- if (remove_path != save_remove_path) {
- efree(remove_path);
- }
}
/* }}} */