Skip to content

Commit

Permalink
Mark resource-like objects as non-comparable
Browse files Browse the repository at this point in the history
As these hold on to some internal resource, there can't be two
"equal" objects with different identity. Make sure the lack of
public properties doesn't result in these being treated as always
equal.
  • Loading branch information
nikic committed Feb 16, 2021
1 parent cb9785a commit b63ea10
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ PHP_MINIT_FUNCTION(curl)
curl_object_handlers.get_constructor = curl_get_constructor;
curl_object_handlers.clone_obj = curl_clone_obj;
curl_object_handlers.cast_object = curl_cast_object;
curl_object_handlers.compare = zend_objects_not_comparable;

curl_multi_register_class(class_CurlMultiHandle_methods);
curl_share_register_class(class_CurlShareHandle_methods);
Expand Down
1 change: 1 addition & 0 deletions ext/curl/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,4 +603,5 @@ void curl_multi_register_class(const zend_function_entry *method_entries) {
curl_multi_handlers.get_constructor = curl_multi_get_constructor;
curl_multi_handlers.clone_obj = NULL;
curl_multi_handlers.cast_object = curl_cast_object;
curl_multi_handlers.compare = zend_objects_not_comparable;
}
1 change: 1 addition & 0 deletions ext/curl/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,5 @@ void curl_share_register_class(const zend_function_entry *method_entries) {
curl_share_handlers.free_obj = curl_share_free_obj;
curl_share_handlers.get_constructor = curl_share_get_constructor;
curl_share_handlers.clone_obj = NULL;
curl_share_handlers.compare = zend_objects_not_comparable;
}
2 changes: 2 additions & 0 deletions ext/enchant/enchant.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ PHP_MINIT_FUNCTION(enchant)
enchant_broker_handlers.offset = XtOffsetOf(enchant_broker, std);
enchant_broker_handlers.free_obj = php_enchant_broker_free;
enchant_broker_handlers.clone_obj = NULL;
enchant_broker_handlers.compare = zend_objects_not_comparable;

INIT_CLASS_ENTRY(dce, "EnchantDictionary", class_EnchantDictionary_methods);
enchant_dict_ce = zend_register_internal_class(&dce);
Expand All @@ -211,6 +212,7 @@ PHP_MINIT_FUNCTION(enchant)
enchant_dict_handlers.offset = XtOffsetOf(enchant_dict, std);
enchant_dict_handlers.free_obj = php_enchant_dict_free;
enchant_dict_handlers.clone_obj = NULL;
enchant_dict_handlers.compare = zend_objects_not_comparable;

REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT | CONST_DEPRECATED);
REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT | CONST_DEPRECATED);
Expand Down
1 change: 1 addition & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ static void php_gd_object_minit_helper()
php_gd_image_object_handlers.clone_obj = NULL;
php_gd_image_object_handlers.free_obj = php_gd_image_object_free;
php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor;
php_gd_image_object_handlers.compare = zend_objects_not_comparable;
php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std);
}

Expand Down
3 changes: 3 additions & 0 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ PHP_MINIT_FUNCTION(openssl)
php_openssl_certificate_object_handlers.free_obj = php_openssl_certificate_free_obj;
php_openssl_certificate_object_handlers.get_constructor = php_openssl_certificate_get_constructor;
php_openssl_certificate_object_handlers.clone_obj = NULL;
php_openssl_certificate_object_handlers.compare = zend_objects_not_comparable;

zend_class_entry csr_ce;
INIT_CLASS_ENTRY(csr_ce, "OpenSSLCertificateSigningRequest", class_OpenSSLCertificateSigningRequest_methods);
Expand All @@ -1130,6 +1131,7 @@ PHP_MINIT_FUNCTION(openssl)
php_openssl_request_object_handlers.free_obj = php_openssl_request_free_obj;
php_openssl_request_object_handlers.get_constructor = php_openssl_request_get_constructor;
php_openssl_request_object_handlers.clone_obj = NULL;
php_openssl_request_object_handlers.compare = zend_objects_not_comparable;

zend_class_entry key_ce;
INIT_CLASS_ENTRY(key_ce, "OpenSSLAsymmetricKey", class_OpenSSLAsymmetricKey_methods);
Expand All @@ -1144,6 +1146,7 @@ PHP_MINIT_FUNCTION(openssl)
php_openssl_pkey_object_handlers.free_obj = php_openssl_pkey_free_obj;
php_openssl_pkey_object_handlers.get_constructor = php_openssl_pkey_get_constructor;
php_openssl_pkey_object_handlers.clone_obj = NULL;
php_openssl_pkey_object_handlers.compare = zend_objects_not_comparable;

#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
OPENSSL_config(NULL);
Expand Down
1 change: 1 addition & 0 deletions ext/shmop/shmop.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ PHP_MINIT_FUNCTION(shmop)
shmop_object_handlers.free_obj = shmop_free_obj;
shmop_object_handlers.get_constructor = shmop_get_constructor;
shmop_object_handlers.clone_obj = NULL;
shmop_object_handlers.compare = zend_objects_not_comparable;

return SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ static PHP_MINIT_FUNCTION(sockets)
address_info_object_handlers.free_obj = address_info_free_obj;
address_info_object_handlers.get_constructor = address_info_get_constructor;
address_info_object_handlers.clone_obj = NULL;
address_info_object_handlers.compare = zend_objects_not_comparable;

REGISTER_LONG_CONSTANT("AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("AF_INET", AF_INET, CONST_CS | CONST_PERSISTENT);
Expand Down
1 change: 1 addition & 0 deletions ext/sysvmsg/sysvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ PHP_MINIT_FUNCTION(sysvmsg)
sysvmsg_queue_object_handlers.free_obj = sysvmsg_queue_free_obj;
sysvmsg_queue_object_handlers.get_constructor = sysvmsg_queue_get_constructor;
sysvmsg_queue_object_handlers.clone_obj = NULL;
sysvmsg_queue_object_handlers.compare = zend_objects_not_comparable;

REGISTER_LONG_CONSTANT("MSG_IPC_NOWAIT", PHP_MSG_IPC_NOWAIT, CONST_PERSISTENT|CONST_CS);
REGISTER_LONG_CONSTANT("MSG_EAGAIN", EAGAIN, CONST_PERSISTENT|CONST_CS);
Expand Down
1 change: 1 addition & 0 deletions ext/sysvsem/sysvsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ PHP_MINIT_FUNCTION(sysvsem)
sysvsem_object_handlers.free_obj = sysvsem_free_obj;
sysvsem_object_handlers.get_constructor = sysvsem_get_constructor;
sysvsem_object_handlers.clone_obj = NULL;
sysvsem_object_handlers.compare = zend_objects_not_comparable;

return SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions ext/sysvshm/sysvshm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ PHP_MINIT_FUNCTION(sysvshm)
sysvshm_object_handlers.free_obj = sysvshm_free_obj;
sysvshm_object_handlers.get_constructor = sysvshm_get_constructor;
sysvshm_object_handlers.clone_obj = NULL;
sysvshm_object_handlers.compare = zend_objects_not_comparable;

if (cfg_get_long("sysvshm.init_mem", &php_sysvshm.init_mem) == FAILURE) {
php_sysvshm.init_mem=10000;
Expand Down
1 change: 1 addition & 0 deletions ext/xml/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ PHP_MINIT_FUNCTION(xml)
xml_parser_object_handlers.get_gc = xml_parser_get_gc;
xml_parser_object_handlers.get_constructor = xml_parser_get_constructor;
xml_parser_object_handlers.clone_obj = NULL;
xml_parser_object_handlers.compare = zend_objects_not_comparable;

REGISTER_LONG_CONSTANT("XML_ERROR_NONE", XML_ERROR_NONE, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XML_ERROR_NO_MEMORY", XML_ERROR_NO_MEMORY, CONST_CS|CONST_PERSISTENT);
Expand Down
2 changes: 2 additions & 0 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ static PHP_MINIT_FUNCTION(zlib)
inflate_context_object_handlers.free_obj = inflate_context_free_obj;
inflate_context_object_handlers.get_constructor = inflate_context_get_constructor;
inflate_context_object_handlers.clone_obj = NULL;
inflate_context_object_handlers.compare = zend_objects_not_comparable;

zend_class_entry deflate_ce;
INIT_CLASS_ENTRY(deflate_ce, "DeflateContext", class_DeflateContext_methods);
Expand All @@ -1364,6 +1365,7 @@ static PHP_MINIT_FUNCTION(zlib)
deflate_context_object_handlers.free_obj = deflate_context_free_obj;
deflate_context_object_handlers.get_constructor = deflate_context_get_constructor;
deflate_context_object_handlers.clone_obj = NULL;
deflate_context_object_handlers.compare = zend_objects_not_comparable;

REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
Expand Down

0 comments on commit b63ea10

Please sign in to comment.