mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Use format string to cut off filename instead of duplicating memory
Split off from GH-17240.
This commit is contained in:
parent
466c8b0e03
commit
b09ed9a0f2
1 changed files with 2 additions and 7 deletions
|
@ -4169,9 +4169,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
|
||||||
if (virtual_file_ex(&new_state, entry->filename, NULL, CWD_EXPAND) != 0 ||
|
if (virtual_file_ex(&new_state, entry->filename, NULL, CWD_EXPAND) != 0 ||
|
||||||
new_state.cwd_length <= 1) {
|
new_state.cwd_length <= 1) {
|
||||||
if (EINVAL == errno && entry->filename_len > 50) {
|
if (EINVAL == errno && entry->filename_len > 50) {
|
||||||
char *tmp = estrndup(entry->filename, 50);
|
spprintf(error, 4096, "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem", entry->filename, dest);
|
||||||
spprintf(error, 4096, "Cannot extract \"%s...\" to \"%s...\", extracted filename is too long for filesystem", tmp, dest);
|
|
||||||
efree(tmp);
|
|
||||||
} else {
|
} else {
|
||||||
spprintf(error, 4096, "Cannot extract \"%s\", internal error", entry->filename);
|
spprintf(error, 4096, "Cannot extract \"%s\", internal error", entry->filename);
|
||||||
}
|
}
|
||||||
|
@ -4196,13 +4194,10 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
|
||||||
len = spprintf(&fullpath, 0, "%s/%s", dest, filename);
|
len = spprintf(&fullpath, 0, "%s/%s", dest, filename);
|
||||||
|
|
||||||
if (len >= MAXPATHLEN) {
|
if (len >= MAXPATHLEN) {
|
||||||
char *tmp;
|
|
||||||
/* truncate for error message */
|
/* truncate for error message */
|
||||||
fullpath[50] = '\0';
|
fullpath[50] = '\0';
|
||||||
if (entry->filename_len > 50) {
|
if (entry->filename_len > 50) {
|
||||||
tmp = estrndup(entry->filename, 50);
|
spprintf(error, 4096, "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem", entry->filename, fullpath);
|
||||||
spprintf(error, 4096, "Cannot extract \"%s...\" to \"%s...\", extracted filename is too long for filesystem", tmp, fullpath);
|
|
||||||
efree(tmp);
|
|
||||||
} else {
|
} else {
|
||||||
spprintf(error, 4096, "Cannot extract \"%s\" to \"%s...\", extracted filename is too long for filesystem", entry->filename, fullpath);
|
spprintf(error, 4096, "Cannot extract \"%s\" to \"%s...\", extracted filename is too long for filesystem", entry->filename, fullpath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue