Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 16 additions & 48 deletions ext/phar/tar.c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly move where the bail: label is? It is somewhat confusing that we go "back up" to do error handling rather than the usual "go to end of function" style for error handling. As I needed to look up the full function code to locate the label.

May be a follow-up PR/commit or be a new commit in this change set.

Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
}

Expand All @@ -337,9 +335,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

hdr = (tar_header*) buf;
Expand All @@ -365,9 +361,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (invalid entry size)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
entry.filename = zend_string_alloc(entry.uncompressed_filesize, myphar->is_persistent);
if (myphar->is_persistent) {
Expand All @@ -381,9 +375,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

/* skip blank stuff */
Expand All @@ -396,9 +388,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

read = php_stream_read(fp, buf, sizeof(buf));
Expand All @@ -408,9 +398,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
continue;
} else if (!last_was_longlink && !old && hdr->prefix[0] != 0) {
Expand Down Expand Up @@ -470,9 +458,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (checksum mismatch of file \"%s\")", fname, ZSTR_VAL(entry.filename));
}
zend_string_release_ex(entry.filename, myphar->is_persistent);
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

uint32_t entry_mode = phar_tar_oct_number(hdr->mode, sizeof(hdr->mode));
Expand Down Expand Up @@ -503,9 +489,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file - hard link to non-existent file \"%.*s\"", fname, (int)linkname_len, hdr->linkname);
}
zend_string_release_ex(entry.filename, myphar->is_persistent);
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
entry.link = estrndup(hdr->linkname, linkname_len);
} else if (entry.tar_type == TAR_SYMLINK) {
Expand All @@ -525,9 +509,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: tar-based phar \"%s\" has invalid metadata in magic file \"%s\"", fname, ZSTR_VAL(entry.filename));
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
}

Expand All @@ -537,9 +519,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: tar-based phar \"%s\" has alias that is larger than 511 bytes, cannot process", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

read = php_stream_read(fp, buf, size);
Expand All @@ -558,9 +538,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
spprintf(error, 4096, "phar error: invalid alias \"%s\" in tar-based phar \"%s\"", buf, fname);
}

php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

actual_alias = pestrndup(buf, size, myphar->is_persistent);
Expand All @@ -572,9 +550,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
spprintf(error, 4096, "phar error: Unable to read alias from tar-based phar \"%s\"", fname);
}

php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
}

Expand All @@ -588,9 +564,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
}

Expand All @@ -605,9 +579,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}
}

Expand All @@ -619,12 +591,10 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch

/* ensure signature set */
if (!myphar->is_data && PHAR_G(require_hash) && !myphar->signature) {
php_stream_close(fp);
phar_destroy_phar_data(myphar);
if (error) {
spprintf(error, 0, "tar-based phar \"%s\" does not have a signature", fname);
}
return FAILURE;
goto bail;
}

myphar->fname = pestrndup(fname, fname_len, myphar->is_persistent);
Expand All @@ -651,9 +621,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
if (error) {
spprintf(error, 4096, "phar error: Unable to add tar-based phar \"%s\" to phar registry", fname);
}
php_stream_close(fp);
phar_destroy_phar_data(myphar);
return FAILURE;
goto bail;
}

myphar = actual;
Expand Down