Skip to content

Commit 633af55

Browse files
committed
PHPC-166: Disable (un)serializing of phongo objects
1 parent 457b645 commit 633af55

18 files changed

+46
-16
lines changed

php_phongo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ void php_phongo_new_regex_from_regex_and_options(zval *object, const char *patte
134134

135135
void php_phongo_result_free(php_phongo_result_t *result);
136136

137+
#define PHONGO_CE_INIT(ce) do { \
138+
ce->ce_flags |= ZEND_ACC_FINAL_CLASS; \
139+
ce->serialize = zend_class_serialize_deny; \
140+
ce->unserialize = zend_class_unserialize_deny; \
141+
} while(0);
142+
143+
137144
#ifdef PHP_DEBUG
138145
void _phongo_debug_bson(bson_t *bson);
139146
#else

src/MongoDB/BulkWrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ PHP_MINIT_FUNCTION(BulkWrite)
356356
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "BulkWrite", php_phongo_bulkwrite_me);
357357
php_phongo_bulkwrite_ce = zend_register_internal_class(&ce TSRMLS_CC);
358358
php_phongo_bulkwrite_ce->create_object = php_phongo_bulkwrite_create_object;
359-
php_phongo_bulkwrite_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
359+
PHONGO_CE_INIT(php_phongo_bulkwrite_ce);
360360

361361
memcpy(&php_phongo_handler_bulkwrite, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
362362
php_phongo_handler_bulkwrite.get_debug_info = php_phongo_bulkwrite_get_debug_info;

src/MongoDB/Command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ PHP_MINIT_FUNCTION(Command)
156156
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Command", php_phongo_command_me);
157157
php_phongo_command_ce = zend_register_internal_class(&ce TSRMLS_CC);
158158
php_phongo_command_ce->create_object = php_phongo_command_create_object;
159-
php_phongo_command_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
159+
PHONGO_CE_INIT(php_phongo_command_ce);
160160

161161
memcpy(&php_phongo_handler_command, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
162162
php_phongo_handler_command.get_debug_info = php_phongo_command_get_debug_info;

src/MongoDB/ConnectionTimeoutException.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PHP_MINIT_FUNCTION(ConnectionTimeoutException)
6363

6464
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "ConnectionTimeoutException", php_phongo_connectiontimeoutexception_me);
6565
php_phongo_connectiontimeoutexception_ce = zend_register_internal_class_ex(&ce, php_phongo_connectionexception_ce, NULL TSRMLS_CC);
66-
php_phongo_connectiontimeoutexception_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
66+
PHONGO_CE_INIT(php_phongo_connectiontimeoutexception_ce);
6767

6868
return SUCCESS;
6969
}

src/MongoDB/CursorId.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ PHP_MINIT_FUNCTION(CursorId)
168168
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "CursorId", php_phongo_cursorid_me);
169169
php_phongo_cursorid_ce = zend_register_internal_class(&ce TSRMLS_CC);
170170
php_phongo_cursorid_ce->create_object = php_phongo_cursorid_create_object;
171-
php_phongo_cursorid_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
171+
PHONGO_CE_INIT(php_phongo_cursorid_ce);
172172

173173
memcpy(&php_phongo_handler_cursorid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
174174
php_phongo_handler_cursorid.get_debug_info = php_phongo_cursorid_get_debug_info;

src/MongoDB/DuplicateKeyException.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PHP_MINIT_FUNCTION(DuplicateKeyException)
6363

6464
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "DuplicateKeyException", php_phongo_duplicatekeyexception_me);
6565
php_phongo_duplicatekeyexception_ce = zend_register_internal_class_ex(&ce, php_phongo_writeexception_ce, NULL TSRMLS_CC);
66-
php_phongo_duplicatekeyexception_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
66+
PHONGO_CE_INIT(php_phongo_duplicatekeyexception_ce);
6767

6868
return SUCCESS;
6969
}

src/MongoDB/ExecutionTimeoutException.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PHP_MINIT_FUNCTION(ExecutionTimeoutException)
6363

6464
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "ExecutionTimeoutException", php_phongo_executiontimeoutexception_me);
6565
php_phongo_executiontimeoutexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
66-
php_phongo_executiontimeoutexception_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
66+
PHONGO_CE_INIT(php_phongo_executiontimeoutexception_ce);
6767

6868
return SUCCESS;
6969
}

src/MongoDB/Manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ PHP_MINIT_FUNCTION(Manager)
572572
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Manager", php_phongo_manager_me);
573573
php_phongo_manager_ce = zend_register_internal_class(&ce TSRMLS_CC);
574574
php_phongo_manager_ce->create_object = php_phongo_manager_create_object;
575-
php_phongo_manager_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
575+
PHONGO_CE_INIT(php_phongo_manager_ce);
576576

577577
memcpy(&php_phongo_handler_manager, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
578578
php_phongo_handler_manager.get_debug_info = php_phongo_manager_get_debug_info;

src/MongoDB/Query.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ PHP_MINIT_FUNCTION(Query)
171171
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Query", php_phongo_query_me);
172172
php_phongo_query_ce = zend_register_internal_class(&ce TSRMLS_CC);
173173
php_phongo_query_ce->create_object = php_phongo_query_create_object;
174-
php_phongo_query_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
174+
PHONGO_CE_INIT(php_phongo_query_ce);
175175

176176
memcpy(&php_phongo_handler_query, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
177177
php_phongo_handler_query.get_debug_info = php_phongo_query_get_debug_info;

src/MongoDB/ReadPreference.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ PHP_MINIT_FUNCTION(ReadPreference)
167167
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "ReadPreference", php_phongo_readpreference_me);
168168
php_phongo_readpreference_ce = zend_register_internal_class(&ce TSRMLS_CC);
169169
php_phongo_readpreference_ce->create_object = php_phongo_readpreference_create_object;
170-
php_phongo_readpreference_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
170+
PHONGO_CE_INIT(php_phongo_readpreference_ce);
171171

172172
memcpy(&php_phongo_handler_readpreference, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
173173
php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info;

0 commit comments

Comments
 (0)