Skip to content

Commit a624c2b

Browse files
committed
Use serialize_deny for CURLFile
Instead of a throwing __wakeup() method.
1 parent 4341795 commit a624c2b

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP 7.4 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- Curl:
23+
. Attempting to serialize a CURLFile class will now generate an exception.
24+
Previously the exception was only thrown on unserialization.
25+
2226
- Date:
2327
. Calling var_dump() or similar on a DateTime(Immutable) instance will no
2428
longer leave behind accessible properties on the object.

ext/curl/curl_file.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "php.h"
2424
#include "Zend/zend_exceptions.h"
25+
#include "Zend/zend_interfaces.h"
2526
#include "php_curl.h"
2627
#if HAVE_CURL
2728

@@ -130,16 +131,6 @@ ZEND_METHOD(CURLFile, setPostFilename)
130131
}
131132
/* }}} */
132133

133-
/* {{{ proto CURLFile::__wakeup()
134-
Unserialization handler */
135-
ZEND_METHOD(CURLFile, __wakeup)
136-
{
137-
zend_unset_property(curl_CURLFile_class, ZEND_THIS, "name", sizeof("name")-1);
138-
zend_update_property_string(curl_CURLFile_class, ZEND_THIS, "name", sizeof("name")-1, "");
139-
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0);
140-
}
141-
/* }}} */
142-
143134
ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1)
144135
ZEND_ARG_INFO(0, filename)
145136
ZEND_ARG_INFO(0, mimetype)
@@ -158,7 +149,6 @@ static const zend_function_entry curlfile_funcs[] = {
158149
PHP_ME(CURLFile, setMimeType, arginfo_curlfile_name, ZEND_ACC_PUBLIC)
159150
PHP_ME(CURLFile, getPostFilename, NULL, ZEND_ACC_PUBLIC)
160151
PHP_ME(CURLFile, setPostFilename, arginfo_curlfile_name, ZEND_ACC_PUBLIC)
161-
PHP_ME(CURLFile, __wakeup, NULL, ZEND_ACC_PUBLIC)
162152
PHP_FE_END
163153
};
164154

@@ -167,6 +157,8 @@ void curlfile_register_class(void)
167157
zend_class_entry ce;
168158
INIT_CLASS_ENTRY( ce, "CURLFile", curlfile_funcs );
169159
curl_CURLFile_class = zend_register_internal_class(&ce);
160+
curl_CURLFile_class->serialize = zend_class_serialize_deny;
161+
curl_CURLFile_class->unserialize = zend_class_unserialize_deny;
170162
zend_declare_property_string(curl_CURLFile_class, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
171163
zend_declare_property_string(curl_CURLFile_class, "mime", sizeof("mime")-1, "", ZEND_ACC_PUBLIC);
172164
zend_declare_property_string(curl_CURLFile_class, "postname", sizeof("postname")-1, "", ZEND_ACC_PUBLIC);

ext/curl/tests/bug73147.phpt

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ if (!extension_loaded("curl")) {
1111

1212
$poc = 'a:1:{i:0;O:8:"CURLFile":1:{s:4:"name";R:1;}}';
1313
try {
14-
var_dump(unserialize($poc));
14+
var_dump(unserialize($poc));
1515
} catch(Exception $e) {
16-
echo $e->getMessage();
16+
echo $e->getMessage();
1717
}
1818
?>
19-
--EXPECT--
20-
Unserialization of CURLFile instances is not allowed
19+
--EXPECTF--
20+
Warning: Erroneous data format for unserializing 'CURLFile' in %s on line %d
21+
22+
Notice: unserialize(): Error at offset 27 of 44 bytes in %s on line %d
23+
bool(false)

ext/curl/tests/curl_file_serialize.phpt

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ if (!extension_loaded("curl")) {
88
?>
99
--FILE--
1010
<?php
11-
$data = 'a:2:{s:4:"file";O:8:"CURLFile":3:{s:4:"name";s:13:"testdata1.txt";s:4:"mime";s:0:"";s:8:"postname";s:0:"";}s:4:"data";s:3:"foo";}';
12-
var_dump(unserialize($data));
11+
$file = new CURLFile(__DIR__ . '/curl_testdata1.txt');
12+
var_dump(serialize($file));
1313
?>
1414
--EXPECTF--
15-
Fatal error: Uncaught Exception: Unserialization of CURLFile instances is not allowed in %s
15+
Fatal error: Uncaught Exception: Serialization of 'CURLFile' is not allowed in %s:%d
1616
Stack trace:
17-
#0 [internal function]: CURLFile->__wakeup()
18-
#1 %s
19-
#2 {main}
17+
#0 %s(%d): serialize(Object(CURLFile))
18+
#1 {main}
2019
thrown in %s on line %d

0 commit comments

Comments
 (0)