mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/phar: Refactor phar_create_default_stub()
This commit is contained in:
@@ -2453,42 +2453,48 @@ static int phar_flush_clean_deleted_apply(zval *zv) /* {{{ */
|
||||
|
||||
#include "stub.h" /* Generated phar_get_stub() function from makestub.php script */
|
||||
|
||||
zend_string *phar_create_default_stub(const char *index_php, const char *web_index, char **error) /* {{{ */
|
||||
zend_string *phar_create_default_stub(const zend_string *php_index_str, const zend_string *web_index_str, char **error) /* {{{ */
|
||||
{
|
||||
size_t index_len, web_len;
|
||||
const char *php_index;
|
||||
const char *web_index;
|
||||
size_t php_len, web_len;
|
||||
|
||||
if (error) {
|
||||
*error = NULL;
|
||||
}
|
||||
|
||||
if (!index_php) {
|
||||
index_php = "index.php";
|
||||
if (!php_index_str) {
|
||||
php_index = "index.php";
|
||||
php_len = strlen("index.php");
|
||||
} else {
|
||||
php_index = ZSTR_VAL(php_index_str);
|
||||
php_len = ZSTR_LEN(php_index_str);
|
||||
if (php_len > 400) {
|
||||
/* ridiculous size not allowed for index.php startup filename */
|
||||
if (error) {
|
||||
spprintf(error, 0, "Illegal filename passed in for stub creation, was %zd characters long, and only 400 or less is allowed", php_len);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!web_index) {
|
||||
if (!web_index_str) {
|
||||
web_index = "index.php";
|
||||
}
|
||||
web_len = strlen("index.php");
|
||||
} else {
|
||||
web_index = ZSTR_VAL(web_index_str);
|
||||
web_len = ZSTR_LEN(web_index_str);
|
||||
|
||||
index_len = strlen(index_php);
|
||||
web_len = strlen(web_index);
|
||||
|
||||
if (index_len > 400) {
|
||||
/* ridiculous size not allowed for index.php startup filename */
|
||||
if (error) {
|
||||
spprintf(error, 0, "Illegal filename passed in for stub creation, was %zd characters long, and only 400 or less is allowed", index_len);
|
||||
if (web_len > 400) {
|
||||
/* ridiculous size not allowed for index.php startup filename */
|
||||
if (error) {
|
||||
spprintf(error, 0, "Illegal web filename passed in for stub creation, was %zd characters long, and only 400 or less is allowed", web_len);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (web_len > 400) {
|
||||
/* ridiculous size not allowed for index.php startup filename */
|
||||
if (error) {
|
||||
spprintf(error, 0, "Illegal web filename passed in for stub creation, was %zd characters long, and only 400 or less is allowed", web_len);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return phar_get_stub(index_php, web_index, index_len+1, web_len+1);
|
||||
return phar_get_stub(php_index, web_index, php_len+1, web_len+1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ zend_result phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t s
|
||||
ZEND_ATTRIBUTE_NONNULL zend_result phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, size_t *signature_length, char **error);
|
||||
|
||||
/* utility functions */
|
||||
zend_string *phar_create_default_stub(const char *index_php, const char *web_index, char **error);
|
||||
zend_string *phar_create_default_stub(const zend_string *php_index_str, const zend_string *web_index_str, char **error);
|
||||
const char *phar_decompress_filter(const phar_entry_info *entry, bool return_unknown);
|
||||
const char *phar_compress_filter(const phar_entry_info *entry, bool return_unknown);
|
||||
|
||||
|
||||
@@ -946,11 +946,11 @@ PHP_METHOD(Phar, interceptFileFuncs)
|
||||
*/
|
||||
PHP_METHOD(Phar, createDefaultStub)
|
||||
{
|
||||
char *index = NULL, *webindex = NULL, *error;
|
||||
zend_string *index = NULL, *webindex = NULL;
|
||||
char *error;
|
||||
zend_string *stub;
|
||||
size_t index_len = 0, webindex_len = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p!p!", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|P!P!", &index, &webindex) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
@@ -2914,12 +2914,11 @@ PHP_METHOD(Phar, setStub)
|
||||
*/
|
||||
PHP_METHOD(Phar, setDefaultStub)
|
||||
{
|
||||
char *index = NULL, *webindex = NULL, *error = NULL;
|
||||
zend_string *index = NULL, *webindex = NULL;
|
||||
zend_string *stub = NULL;
|
||||
size_t index_len = 0, webindex_len = 0;
|
||||
bool created_stub = false;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|P!P!", &index, &webindex) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
@@ -2947,6 +2946,7 @@ PHP_METHOD(Phar, setDefaultStub)
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
char *error = NULL;
|
||||
if (!phar_obj->archive->is_tar && !phar_obj->archive->is_zip) {
|
||||
stub = phar_create_default_stub(index, webindex, &error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user