1
0
Fork 0

finished sandbox rewrite

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@938 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
This commit is contained in:
Xuefer 2012-06-28 10:17:58 +00:00
parent ac328888f0
commit f5672a77eb
4 changed files with 44 additions and 20 deletions

View File

@ -32,7 +32,7 @@ static void xc_dasm(zval *output, zend_op_array *op_array TSRMLS_DC) /* {{{ */
ALLOC_INIT_ZVAL(list);
array_init(list);
for (b = xc_sandbox_user_function_begin(); b; b = b->pListNext) {
for (b = xc_sandbox_user_function_begin(TSRMLS_C); b; b = b->pListNext) {
int keysize, keyLength;
ALLOC_INIT_ZVAL(zv);
@ -68,7 +68,7 @@ static void xc_dasm(zval *output, zend_op_array *op_array TSRMLS_DC) /* {{{ */
ALLOC_INIT_ZVAL(list);
array_init(list);
for (b = xc_sandbox_user_class_begin(); b; b = b->pListNext) {
for (b = xc_sandbox_user_class_begin(TSRMLS_C); b; b = b->pListNext) {
int keysize, keyLength;
ALLOC_INIT_ZVAL(zv);

46
utils.c
View File

@ -764,7 +764,7 @@ void xc_copy_internal_zend_constants(HashTable *target, HashTable *source) /* {{
/* }}} */
#endif
xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) char *filename TSRMLS_DC) /* {{{ */
static xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) char *filename TSRMLS_DC) /* {{{ */
{
HashTable *h;
@ -929,7 +929,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */
zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL);
}
/* }}} */
void xc_sandbox_free(xc_sandbox_t *sandbox, zend_op_array *op_array TSRMLS_DC) /* {{{ */
static void xc_sandbox_free(xc_sandbox_t *sandbox, zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
XG(sandbox) = NULL;
#ifdef XCACHE_ERROR_CACHING
@ -997,34 +997,58 @@ void xc_sandbox_free(xc_sandbox_t *sandbox, zend_op_array *op_array TSRMLS_DC) /
#endif
}
/* }}} */
const Bucket *xc_sandbox_user_function_begin() /* {{{ */
zend_op_array *xc_sandbox(xc_sandboxed_func_t sandboxed_func, void *data, ZEND_24(NOTHING, const) char *filename TSRMLS_DC) /* {{{ */
{
xc_sandbox_t sandbox;
zend_op_array *op_array = NULL;
zend_bool catched = 0;
memset(&sandbox, 0, sizeof(sandbox));
zend_try {
xc_sandbox_init(&sandbox, filename TSRMLS_CC);
op_array = sandboxed_func(data TSRMLS_CC);
} zend_catch {
catched = 1;
} zend_end_try();
xc_sandbox_free(&sandbox, op_array TSRMLS_CC);
if (catched) {
zend_bailout();
}
return op_array;
}
/* {{{ */
const Bucket *xc_sandbox_user_function_begin(TSRMLS_D) /* {{{ */
{
xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox);
return TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead;
} /* {{{ */
const Bucket *xc_sandbox_user_class_begin() /* {{{ */
}
/* {{{ */
const Bucket *xc_sandbox_user_class_begin(TSRMLS_D) /* {{{ */
{
xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox);
return TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead;
} /* {{{ */
}
/* {{{ */
#ifdef XCACHE_ERROR_CACHING
xc_compilererror_t *xc_sandbox_compilererrors() /* {{{ */
xc_compilererror_t *xc_sandbox_compilererrors(TSRMLS_D) /* {{{ */
{
xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox);
return sandbox->compilererrors;
} /* }}} */
zend_uint xc_sandbox_compilererror_cnt() /* {{{ */
}
/* }}} */
zend_uint xc_sandbox_compilererror_cnt(TSRMLS_D) /* {{{ */
{
xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox);
return sandbox->compilererror_cnt;
} /* }}} */
}
/* }}} */
#endif
int xc_vtrace(const char *fmt, va_list args) /* {{{ */
{
return vfprintf(stderr, fmt, args);

10
utils.h
View File

@ -82,12 +82,12 @@ ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(NOTHING, const) char *filename,
/* return op_array to install */
typedef zend_op_array *(*xc_sandboxed_func_t)(void *data TSRMLS_DC);
zend_op_array *xc_sandbox(xc_sandboxed_func_t sandboxed_func, void *data, ZEND_24(NOTHING, const) char *filename TSRMLS_DC);
const Bucket *xc_sandbox_user_function_begin();
const Bucket *xc_sandbox_user_class_begin();
zend_uint xc_sandbox_compilererror_cnt();
const Bucket *xc_sandbox_user_function_begin(TSRMLS_D);
const Bucket *xc_sandbox_user_class_begin(TSRMLS_D);
zend_uint xc_sandbox_compilererror_cnt(TSRMLS_D);
#ifdef XCACHE_ERROR_CACHING
xc_compilererror_t *xc_sandbox_compilererrors();
zend_uint xc_sandbox_compilererror_cnt();
xc_compilererror_t *xc_sandbox_compilererrors(TSRMLS_D);
zend_uint xc_sandbox_compilererror_cnt(TSRMLS_D);
#endif
void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce));

View File

@ -1809,8 +1809,8 @@ static void xc_compile_php(xc_compiler_t *compiler, zend_file_handle *h, int typ
}
/* }}} */
#ifdef XCACHE_ERROR_CACHING
compiler->new_php.compilererrors = xc_sandbox_compilererrors();
compiler->new_php.compilererror_cnt = xc_sandbox_compilererror_cnt();
compiler->new_php.compilererrors = xc_sandbox_compilererrors(TSRMLS_C);
compiler->new_php.compilererror_cnt = xc_sandbox_compilererror_cnt(TSRMLS_C);
#endif
#ifndef ZEND_COMPILE_DELAYED_BINDING
/* {{{ find inherited classes that should be early-binding */