Skip to content

Commit 69bc197

Browse files
committed
PHPC-190: Provide __wakeUp() to disable unserialize()
1 parent 45bf77c commit 69bc197

File tree

11 files changed

+26
-0
lines changed

11 files changed

+26
-0
lines changed

php_phongo_classes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ extern PHONGO_API zend_class_entry *php_phongo_regex_ce;
223223
extern PHONGO_API zend_class_entry *php_phongo_timestamp_ce;
224224
extern PHONGO_API zend_class_entry *php_phongo_utcdatetime_ce;
225225

226+
/* Shared accross all MongoDB\Driver objects to disable unserialize() */
227+
PHP_METHOD(Manager, __wakeUp);
228+
226229
PHP_MINIT_FUNCTION(Command);
227230
PHP_MINIT_FUNCTION(Cursor);
228231
PHP_MINIT_FUNCTION(CursorId);

src/MongoDB/BulkWrite.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static zend_function_entry php_phongo_bulkwrite_me[] = {
254254
PHP_ME(BulkWrite, update, ai_BulkWrite_update, ZEND_ACC_PUBLIC)
255255
PHP_ME(BulkWrite, delete, ai_BulkWrite_delete, ZEND_ACC_PUBLIC)
256256
PHP_ME(BulkWrite, count, ai_BulkWrite_count, ZEND_ACC_PUBLIC)
257+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
257258
PHP_FE_END
258259
};
259260

src/MongoDB/Command.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ ZEND_END_ARG_INFO();
8484

8585
static zend_function_entry php_phongo_command_me[] = {
8686
PHP_ME(Command, __construct, ai_Command___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
87+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
8788
PHP_FE_END
8889
};
8990

src/MongoDB/CursorId.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ZEND_END_ARG_INFO();
105105
static zend_function_entry php_phongo_cursorid_me[] = {
106106
PHP_ME(CursorId, __construct, ai_CursorId___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
107107
PHP_ME(CursorId, __toString, ai_CursorId___toString, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
108+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
108109
PHP_FE_END
109110
};
110111

src/MongoDB/Manager.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ PHP_METHOD(Manager, getServers)
277277
}
278278
}
279279
/* }}} */
280+
/* {{{ proto void MongoDB\Driver\Manager::__wakeUp()
281+
* Throws MongoDB\Driver\RuntimeException as it cannot be serialized */
282+
PHP_METHOD(Manager, __wakeUp)
283+
{
284+
(void)return_value_ptr; (void)return_value_used; (void)return_value; (void)this_ptr;
285+
286+
if (zend_parse_parameters_none() == FAILURE) {
287+
return;
288+
}
289+
290+
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "%s", "MongoDB\\Driver objects cannot be serialized");
291+
}
292+
/* }}} */
280293

281294
/**
282295
* Manager abstracts a cluster of Server objects (i.e. socket connections).
@@ -350,6 +363,7 @@ static zend_function_entry php_phongo_manager_me[] = {
350363
PHP_ME(Manager, executeUpdate, ai_Manager_executeUpdate, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
351364
PHP_ME(Manager, executeDelete, ai_Manager_executeDelete, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
352365
PHP_ME(Manager, getServers, ai_Manager_getServers, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
366+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
353367
PHP_FE_END
354368
};
355369

src/MongoDB/Query.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ZEND_END_ARG_INFO();
8181

8282
static zend_function_entry php_phongo_query_me[] = {
8383
PHP_ME(Query, __construct, ai_Query___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
84+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
8485
PHP_FE_END
8586
};
8687

src/MongoDB/Result.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static zend_function_entry php_phongo_result_me[] = {
190190
PHP_ME(Result, getIterator, ai_Result_getIterator, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
191191
PHP_ME(Result, toArray, ai_Result_toArray, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
192192
PHP_ME(Result, getServer, ai_Result_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
193+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
193194
PHP_FE_END
194195
};
195196

src/MongoDB/Server.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ static zend_function_entry php_phongo_server_me[] = {
455455
PHP_ME(Server, isArbiter, ai_Server_isArbiter, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
456456
PHP_ME(Server, isHidden, ai_Server_isHidden, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
457457
PHP_ME(Server, isPassive, ai_Server_isPassive, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
458+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
458459
PHP_FE_END
459460
};
460461

src/MongoDB/WriteConcernError.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static zend_function_entry php_phongo_writeconcernerror_me[] = {
118118
PHP_ME(WriteConcernError, getCode, ai_WriteConcernError_getCode, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
119119
PHP_ME(WriteConcernError, getInfo, ai_WriteConcernError_getInfo, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
120120
PHP_ME(WriteConcernError, getMessage, ai_WriteConcernError_getMessage, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
121+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
121122
PHP_FE_END
122123
};
123124

src/MongoDB/WriteError.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static zend_function_entry php_phongo_writeerror_me[] = {
140140
PHP_ME(WriteError, getIndex, ai_WriteError_getIndex, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
141141
PHP_ME(WriteError, getMessage, ai_WriteError_getMessage, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
142142
PHP_ME(WriteError, getInfo, ai_WriteError_getInfo, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
143+
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
143144
PHP_FE_END
144145
};
145146

0 commit comments

Comments
 (0)