Skip to content

Commit d105958

Browse files
committed
Only use FCC for SQLite3 user defined authorizer
1 parent 37aea43 commit d105958

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

ext/sqlite3/php_sqlite3_structs.h

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ typedef struct _php_sqlite3_db_object {
6666
sqlite3 *db;
6767
php_sqlite3_func *funcs;
6868
php_sqlite3_collation *collations;
69-
zend_fcall_info authorizer_fci;
7069
zend_fcall_info_cache authorizer_fcc;
7170

7271
bool exception;

ext/sqlite3/sqlite3.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ PHP_METHOD(SQLite3, open)
155155
#endif
156156

157157
db_obj->initialised = 1;
158-
db_obj->authorizer_fci = empty_fcall_info;
159158
db_obj->authorizer_fcc = empty_fcall_info_cache;
160159

161160
sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, db_obj);
@@ -1288,16 +1287,14 @@ PHP_METHOD(SQLite3, setAuthorizer)
12881287
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
12891288

12901289
/* Clear previously set callback */
1291-
if (ZEND_FCI_INITIALIZED(db_obj->authorizer_fci)) {
1292-
zval_ptr_dtor(&db_obj->authorizer_fci.function_name);
1293-
db_obj->authorizer_fci.size = 0;
1290+
if (ZEND_FCC_INITIALIZED(db_obj->authorizer_fcc)) {
1291+
zend_fcc_dtor(&db_obj->authorizer_fcc);
12941292
}
12951293

12961294
/* Only enable userland authorizer if argument is not NULL */
12971295
if (ZEND_FCI_INITIALIZED(fci)) {
1298-
db_obj->authorizer_fci = fci;
1299-
Z_ADDREF(db_obj->authorizer_fci.function_name);
13001296
db_obj->authorizer_fcc = fcc;
1297+
zend_fcc_addref(&db_obj->authorizer_fcc);
13011298
}
13021299

13031300
RETURN_TRUE;
@@ -2064,10 +2061,9 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
20642061
}
20652062

20662063
php_sqlite3_db_object *db_obj = (php_sqlite3_db_object *)autharg;
2067-
zend_fcall_info *fci = &db_obj->authorizer_fci;
20682064

20692065
/* fallback to access allowed if authorizer callback is not defined */
2070-
if (fci->size == 0) {
2066+
if (!ZEND_FCC_INITIALIZED(db_obj->authorizer_fcc)) {
20712067
return SQLITE_OK;
20722068
}
20732069

@@ -2101,13 +2097,10 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
21012097
ZVAL_STRING(&argv[4], arg4);
21022098
}
21032099

2104-
fci->retval = &retval;
2105-
fci->param_count = 5;
2106-
fci->params = argv;
2107-
21082100
int authreturn = SQLITE_DENY;
21092101

2110-
if (zend_call_function(fci, &db_obj->authorizer_fcc) != SUCCESS || Z_ISUNDEF(retval)) {
2102+
zend_call_known_fcc(&db_obj->authorizer_fcc, &retval, /* argc */ 5, argv, /* named_params */ NULL);
2103+
if (Z_ISUNDEF(retval)) {
21112104
php_sqlite3_error(db_obj, "An error occurred while invoking the authorizer callback");
21122105
} else {
21132106
if (Z_TYPE(retval) != IS_LONG) {
@@ -2122,8 +2115,13 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
21222115
}
21232116
}
21242117

2125-
zend_fcall_info_args_clear(fci, 0);
2118+
/* Free local return and argument values */
21262119
zval_ptr_dtor(&retval);
2120+
zval_ptr_dtor(&argv[0]);
2121+
zval_ptr_dtor(&argv[1]);
2122+
zval_ptr_dtor(&argv[2]);
2123+
zval_ptr_dtor(&argv[3]);
2124+
zval_ptr_dtor(&argv[4]);
21272125

21282126
return authreturn;
21292127
}
@@ -2165,8 +2163,8 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */
21652163
}
21662164

21672165
/* Release function_name from authorizer */
2168-
if (intern->authorizer_fci.size > 0) {
2169-
zval_ptr_dtor(&intern->authorizer_fci.function_name);
2166+
if (ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) {
2167+
zend_fcc_dtor(&intern->authorizer_fcc);
21702168
}
21712169

21722170
while (intern->funcs) {

0 commit comments

Comments
 (0)