Skip to content

Commit b3da40e

Browse files
committed
Only use FCC for SQLite3 user defined authorizer
1 parent 944dd36 commit b3da40e

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

ext/sqlite3/php_sqlite3_structs.h

Lines changed: 0 additions & 1 deletion
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

Lines changed: 15 additions & 16 deletions
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);
@@ -1296,16 +1295,15 @@ PHP_METHOD(SQLite3, setAuthorizer)
12961295
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
12971296

12981297
/* Clear previously set callback */
1299-
if (ZEND_FCI_INITIALIZED(db_obj->authorizer_fci)) {
1300-
zval_ptr_dtor(&db_obj->authorizer_fci.function_name);
1301-
db_obj->authorizer_fci.size = 0;
1298+
if (ZEND_FCC_INITIALIZED(db_obj->authorizer_fcc)) {
1299+
zend_fcc_dtor(&db_obj->authorizer_fcc);
1300+
memcpy(&db_obj->authorizer_fcc, &empty_fcall_info_cache, sizeof(zend_fcall_info_cache));
13021301
}
13031302

13041303
/* Only enable userland authorizer if argument is not NULL */
13051304
if (ZEND_FCI_INITIALIZED(fci)) {
1306-
db_obj->authorizer_fci = fci;
1307-
Z_ADDREF(db_obj->authorizer_fci.function_name);
13081305
db_obj->authorizer_fcc = fcc;
1306+
zend_fcc_addref(&db_obj->authorizer_fcc);
13091307
}
13101308

13111309
RETURN_TRUE;
@@ -2072,10 +2070,9 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
20722070
}
20732071

20742072
php_sqlite3_db_object *db_obj = (php_sqlite3_db_object *)autharg;
2075-
zend_fcall_info *fci = &db_obj->authorizer_fci;
20762073

20772074
/* fallback to access allowed if authorizer callback is not defined */
2078-
if (fci->size == 0) {
2075+
if (!ZEND_FCC_INITIALIZED(db_obj->authorizer_fcc)) {
20792076
return SQLITE_OK;
20802077
}
20812078

@@ -2109,13 +2106,10 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
21092106
ZVAL_STRING(&argv[4], arg4);
21102107
}
21112108

2112-
fci->retval = &retval;
2113-
fci->param_count = 5;
2114-
fci->params = argv;
2115-
21162109
int authreturn = SQLITE_DENY;
21172110

2118-
if (zend_call_function(fci, &db_obj->authorizer_fcc) != SUCCESS || Z_ISUNDEF(retval)) {
2111+
zend_call_known_fcc(&db_obj->authorizer_fcc, &retval, /* argc */ 5, argv, /* named_params */ NULL);
2112+
if (Z_ISUNDEF(retval)) {
21192113
php_sqlite3_error(db_obj, "An error occurred while invoking the authorizer callback");
21202114
} else {
21212115
if (Z_TYPE(retval) != IS_LONG) {
@@ -2130,8 +2124,13 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
21302124
}
21312125
}
21322126

2133-
zend_fcall_info_args_clear(fci, 0);
2127+
/* Free local return and argument values */
21342128
zval_ptr_dtor(&retval);
2129+
zval_ptr_dtor(&argv[0]);
2130+
zval_ptr_dtor(&argv[1]);
2131+
zval_ptr_dtor(&argv[2]);
2132+
zval_ptr_dtor(&argv[3]);
2133+
zval_ptr_dtor(&argv[4]);
21352134

21362135
return authreturn;
21372136
}
@@ -2173,8 +2172,8 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */
21732172
}
21742173

21752174
/* Release function_name from authorizer */
2176-
if (intern->authorizer_fci.size > 0) {
2177-
zval_ptr_dtor(&intern->authorizer_fci.function_name);
2175+
if (ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) {
2176+
zend_fcc_dtor(&intern->authorizer_fcc);
21782177
}
21792178

21802179
while (intern->funcs) {

0 commit comments

Comments
 (0)