Skip to content
Closed
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: 8 additions & 2 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,10 @@ static int curl_ssh_hostkeyfunction(void *clientp, int keytype, const char *key,
php_curl *ch = (php_curl *)clientp;
int rval = CURLKHMATCH_MISMATCH; /* cancel connection in case of an exception */

if (!ZEND_FCC_INITIALIZED(ch->handlers.sshhostkey)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is adjacently related, matches other handlers, otherwise a nulled callback can crash

return rval;
}

#if PHP_CURL_DEBUG
fprintf(stderr, "curl_ssh_hostkeyfunction() called\n");
fprintf(stderr, "clientp = %x, keytype = %d, key = %s, keylen = %zu\n", clientp, keytype, key, keylen);
Expand Down Expand Up @@ -1284,8 +1288,11 @@ static void php_curl_copy_fcc_with_option(php_curl *ch, CURLoption option, zend_
{
if (ZEND_FCC_INITIALIZED(*source_fcc)) {
zend_fcc_dup(target_fcc, source_fcc);
curl_easy_setopt(ch->cp, option, (void *) ch);
}

/* The callback data (i.e. pointer to the curl handle) stays even if a user callback
* is reset to NULL. Ensure the data pointer always points to the new handle. */
curl_easy_setopt(ch->cp, option, (void *) ch);
}

void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
Expand Down Expand Up @@ -1325,7 +1332,6 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *) ch);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is already done now by the php_curl_copy_fcc_with_option CURLOPT_DEBUGDATA code below


php_curl_copy_fcc_with_option(ch, CURLOPT_PROGRESSDATA, &ch->handlers.progress, &source->handlers.progress);
php_curl_copy_fcc_with_option(ch, CURLOPT_XFERINFODATA, &ch->handlers.xferinfo, &source->handlers.xferinfo);
Expand Down
27 changes: 27 additions & 0 deletions ext/curl/tests/curl_copy_handle_progress_null_uaf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Cloning a curl handle whose CURLOPT_PROGRESSFUNCTION was reset to null must not reference the source handle
--EXTENSIONS--
curl
--FILE--
<?php
$srcfile = __DIR__ . '/curl_copy_handle_progress_null_uaf.txt';
file_put_contents($srcfile, "Test.");

$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "file://" . $srcfile);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_NOPROGRESS, false);
curl_setopt($ch1, CURLOPT_PROGRESSFUNCTION, fn() => 0);
curl_setopt($ch1, CURLOPT_PROGRESSFUNCTION, null);

$ch2 = clone $ch1;
unset($ch1);

var_dump(curl_exec($ch2));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/curl_copy_handle_progress_null_uaf.txt');
?>
--EXPECT--
string(5) "Test."
Loading