Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
zval argv[3];
zval retval;

if (!ZEND_FCC_INITIALIZED(ch->handlers.fnmatch)) {
return rval;
}

GC_ADDREF(&ch->std);
ZVAL_OBJ(&argv[0], &ch->std);
ZVAL_STRING(&argv[1], pattern);
Expand Down Expand Up @@ -652,6 +656,9 @@ static int curl_progress(void *clientp, double dltotal, double dlnow, double ult
fprintf(stderr, "curl_progress() called\n");
fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
#endif
if (!ZEND_FCC_INITIALIZED(ch->handlers.progress)) {
return rval;
}
Comment on lines +660 to +661
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand how this can happen. It shouldn't be possible for this state to arise as this condition should be caught by the HANDLE_CURL_OPTION_CALLABLE, no? Or am I missing something here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it is not, when I debugged php_curl_set_callable_handler earlier, the fcc was not initialised despite being succesful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ... is strange. Because this would imply all the other callable options suffer from the same problem. Or do they not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and yes

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_WILDCARDMATCH, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FNMATCH_FUNCTION, $callback);

curl_setopt($ch, CURLOPT_URL, "ftp://ftp.gnu.org/gnu/README*");

$result = curl_exec($ch);
var_dump($result);
curl_close($ch);
sapi/cli/php c.php 

Warning: Undefined variable $callback in /home/dcarlier/php-src/c.php on line 11
/home/dcarlier/php-src/Zend/zend_API.h:847:6: runtime error: member access within null pointer of type 'zend_function' (aka 'union _zend_function')
    #0 0x5e79794f0d3e in zend_call_known_fcc /home/dcarlier/php-src/Zend/zend_API.h:847:6
    #1 0x5e79794f6918 in curl_fnmatch /home/dcarlier/php-src/ext/curl/interface.c:630:2
    #2 0x78a14153345d  (/lib/x86_64-linux-gnu/libcurl.so.4+0x3c45d) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #3 0x78a14153437c  (/lib/x86_64-linux-gnu/libcurl.so.4+0x3d37c) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #4 0x78a14152d1b1  (/lib/x86_64-linux-gnu/libcurl.so.4+0x361b1) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #5 0x78a14152d837  (/lib/x86_64-linux-gnu/libcurl.so.4+0x36837) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #6 0x78a14152d9c3  (/lib/x86_64-linux-gnu/libcurl.so.4+0x369c3) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #7 0x78a141531ce3  (/lib/x86_64-linux-gnu/libcurl.so.4+0x3ace3) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #8 0x78a14152de41  (/lib/x86_64-linux-gnu/libcurl.so.4+0x36e41) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #9 0x78a14157e1c8  (/lib/x86_64-linux-gnu/libcurl.so.4+0x871c8) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #10 0x78a141576e68  (/lib/x86_64-linux-gnu/libcurl.so.4+0x7fe68) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #11 0x78a14158b981  (/lib/x86_64-linux-gnu/libcurl.so.4+0x94981) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #12 0x78a14156f5d6  (/lib/x86_64-linux-gnu/libcurl.so.4+0x785d6) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #13 0x78a141570bab in curl_multi_perform (/lib/x86_64-linux-gnu/libcurl.so.4+0x79bab) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #14 0x78a14153171e  (/lib/x86_64-linux-gnu/libcurl.so.4+0x3a71e) (BuildId: 8b03052c795c3defd8539716e1150b035b0c1a0c)
    #15 0x5e79794d89bc in zif_curl_exec /home/dcarlier/php-src/ext/curl/interface.c:2447:10
    #16 0x5e797cbb6240 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/dcarlier/php-src/Zend/zend_vm_execute.h:1351:2
    #17 0x5e797c758296 in execute_ex /home/dcarlier/php-src/Zend/zend_vm_execute.h:58658:7
    #18 0x5e797c75a04e in zend_execute /home/dcarlier/php-src/Zend/zend_vm_execute.h:64310:2
    #19 0x5e797d31820f in zend_execute_script /home/dcarlier/php-src/Zend/zend.c:1934:3
    #20 0x5e797be6a3c2 in php_execute_script_ex /home/dcarlier/php-src/main/main.c:2577:13
    #21 0x5e797be6b2a8 in php_execute_script /home/dcarlier/php-src/main/main.c:2617:9
    #22 0x5e797d32906b in do_cli /home/dcarlier/php-src/sapi/cli/php_cli.c:935:5
    #23 0x5e797d325081 in main /home/dcarlier/php-src/sapi/cli/php_cli.c:1310:18
    #24 0x78a140c2a574 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #25 0x78a140c2a627 in __libc_start_main csu/../csu/libc-start.c:360:3
    #26 0x5e7978c07d04 in _start (/home/dcarlier/php-src/sapi/cli/php+0x2a07d04) (BuildId: 2a17fa1bdb34187d3865febd5e9d28c620d82802)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/dcarlier/php-src/Zend/zend_API.h:847:6 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna plug the rest of callables..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well that was easy, only fnmatch remained, debug however was already protected apparently.


zval args[5];
zval retval;
Expand Down Expand Up @@ -690,6 +697,9 @@ static int curl_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow, cu
fprintf(stderr, "curl_xferinfo() called\n");
fprintf(stderr, "clientp = %x, dltotal = %ld, dlnow = %ld, ultotal = %ld, ulnow = %ld\n", clientp, dltotal, dlnow, ultotal, ulnow);
#endif
if (!ZEND_FCC_INITIALIZED(ch->handlers.xferinfo)) {
return rval;
}

zval argv[5];
zval retval;
Expand Down
27 changes: 27 additions & 0 deletions ext/curl/tests/gh21023.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-21023 (crash with CURLOPT_XFERINFOFUNCTION set with an invalid callback)
--EXTENSIONS--
curl
--FILE--
<?php
include 'server.inc';
$host = curl_cli_server_start();
$url = "{$host}/get.inc";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_XFERINFOFUNCTION, null);
curl_exec($ch);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, null);
curl_exec($ch);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_WILDCARDMATCH, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FNMATCH_FUNCTION, null);
curl_exec($ch);
echo "OK", PHP_EOL;
?>
--EXPECT--
OK
Loading