From: Dmitry Stogov Date: Mon, 12 May 2014 12:43:18 +0000 (+0400) Subject: ext/phar support (incomplete) X-Git-Tag: POST_PHPNG_MERGE~380^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4288f0486b073c526f6e7575b10d9ffdfdee6173;p=php ext/phar support (incomplete) --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 72593df02a..62b08cc642 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -50,7 +50,7 @@ ZEND_INI_MH(phar_ini_modify_handler) /* {{{ */ { zend_bool old, ini; - if (entry->name_length == 14) { + if (entry->name_length == sizeof("phar.readonly")-1) { old = PHAR_G(readonly_orig); } else { old = PHAR_G(require_hash_orig); @@ -421,14 +421,14 @@ void destroy_phar_manifest_entry_int(phar_entry_info *entry) /* {{{ */ pefree(entry->tmp, entry->is_persistent); entry->tmp = 0; } - - pefree(entry, entry->is_persistent); } /* }}} */ void destroy_phar_manifest_entry(zval *zv) /* {{{ */ { - destroy_phar_manifest_entry_int(Z_PTR_P(zv)); + phar_entry_info *entry = Z_PTR_P(zv); + destroy_phar_manifest_entry_int(entry); + pefree(entry, entry->is_persistent); } /* }}} */ @@ -447,7 +447,7 @@ int phar_entry_delref(phar_entry_data *idata TSRMLS_DC) /* {{{ */ /* if phar_get_or_create_entry_data returns a sub-directory, we have to free it */ if (idata->internal_file->is_temp_dir) { destroy_phar_manifest_entry_int(idata->internal_file); -//??? efree(idata->internal_file); + efree(idata->internal_file); } } @@ -2301,7 +2301,6 @@ int phar_split_fname(const char *filename, int filename_len, char **arch, int *a int phar_open_executed_filename(char *alias, int alias_len, char **error TSRMLS_DC) /* {{{ */ { char *fname; -//??? zval *halt_constant; php_stream *fp; int fname_len; char *actual = NULL; diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 1fc62e9413..978b036c67 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1429,7 +1429,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ if (!value) { /* failure in get_current_data */ - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned no value", ce->name); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned no value", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1440,7 +1440,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ php_stream_from_zval_no_verify(fp, value); if (!fp) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Iterator %v returned an invalid stream handle", ce->name); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Iterator %v returned an invalid stream handle", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1454,7 +1454,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ if (Z_TYPE(key) != IS_STRING) { zval_dtor(&key); - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1464,7 +1464,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ save = str_key; zval_dtor(&key); } else { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1478,7 +1478,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ spl_filesystem_object *intern = (spl_filesystem_object*)((char*)Z_OBJ_P(value) - Z_OBJ_P(value)->handlers->offset); if (!base_len) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Iterator %v returns an SplFileInfo object, so base directory must be specified", ce->name); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Iterator %v returns an SplFileInfo object, so base directory must be specified", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1522,7 +1522,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ } /* fall-through */ default: - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid value (must return a string)", ce->name); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid value (must return a string)", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1562,7 +1562,7 @@ phar_spl_fileinfo: } } else { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a path \"%s\" that is not in the base directory \"%s\"", ce->name, fname, base); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a path \"%s\" that is not in the base directory \"%s\"", ce->name->val, fname, base); if (save) { efree(save); @@ -1582,7 +1582,7 @@ phar_spl_fileinfo: if (Z_TYPE(key) != IS_STRING) { zval_dtor(&key); - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name->val); return ZEND_HASH_APPLY_STOP; } @@ -1592,13 +1592,13 @@ phar_spl_fileinfo: save = str_key; zval_dtor(&key); } else { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned an invalid key (must return a string)", ce->name->val); return ZEND_HASH_APPLY_STOP; } } #if PHP_API_VERSION < 20100412 if (PG(safe_mode) && (!php_checkuid(fname, NULL, CHECKUID_ALLOW_ONLY_FILE))) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a path \"%s\" that safe mode prevents opening", ce->name, fname); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a path \"%s\" that safe mode prevents opening", ce->name->val, fname); if (save) { efree(save); @@ -1613,7 +1613,7 @@ phar_spl_fileinfo: #endif if (php_check_open_basedir(fname TSRMLS_CC)) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a path \"%s\" that open_basedir prevents opening", ce->name, fname); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a path \"%s\" that open_basedir prevents opening", ce->name->val, fname); if (save) { efree(save); @@ -1630,7 +1630,7 @@ phar_spl_fileinfo: fp = php_stream_open_wrapper(fname, "rb", STREAM_MUST_SEEK|0, &opened); if (!fp) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a file that could not be opened \"%s\"", ce->name, fname); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %v returned a file that could not be opened \"%s\"", ce->name->val, fname); if (save) { efree(save); @@ -2246,7 +2246,7 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert phar->alias = source->alias; if (Z_TYPE(source->metadata) != IS_UNDEF) { - zval_copy_ctor(&phar->metadata); + ZVAL_DUP(&phar->metadata, &source->metadata); phar->metadata_len = 0; } @@ -2876,7 +2876,7 @@ PHP_METHOD(Phar, setStub) zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); return; } - phar_flush(phar_obj->archive, (char *) &zstub, len, 0, &error TSRMLS_CC); + phar_flush(phar_obj->archive, (char *) zstub, len, 0, &error TSRMLS_CC); if (error) { zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s", error); efree(error); diff --git a/ext/phar/util.c b/ext/phar/util.c index 85f5f6566b..856a731290 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -227,7 +227,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, if (ssb.sb.st_mode & S_IFDIR) { entry.is_dir = 1; - if (NULL != zend_hash_str_add_ptr(&phar->mounted_dirs, entry.filename, path_len, entry.filename)) { + if (NULL == zend_hash_str_add_ptr(&phar->mounted_dirs, entry.filename, path_len, entry.filename)) { /* directory already mounted */ efree(entry.tmp); efree(entry.filename); @@ -1393,11 +1393,17 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, zend_fcall_info fci; zend_fcall_info_cache fcc; zval retval, zp[3], openssl; + zend_string *str; ZVAL_STRINGL(&openssl, is_sign ? "openssl_sign" : "openssl_verify", is_sign ? sizeof("openssl_sign")-1 : sizeof("openssl_verify")-1); ZVAL_STRINGL(&zp[1], *signature, *signature_len); ZVAL_STRINGL(&zp[2], key, key_len); - ZVAL_STR(&zp[0], php_stream_copy_to_mem(fp, (size_t) end, 0)); + str = php_stream_copy_to_mem(fp, (size_t) end, 0); + if (str) { + ZVAL_STR(&zp[0], str); + } else { + ZVAL_EMPTY_STRING(&zp[0]); + } if (end != Z_STRLEN(zp[0])) { zval_dtor(&zp[0]);