Skip to content

Commit 7acb90c

Browse files
committed
Address review comments
* Fix callback in test * Use appropriate error types * Check for long type * Get rid of else branch
1 parent 40ab8cc commit 7acb90c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

ext/curl/interface.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,16 @@ static int curl_ssh_hostkeyfunction(void *clientp, int keytype, const char *key,
801801
php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_SSH_HOSTKEYFUNCTION");
802802
} else if (!Z_ISUNDEF(retval)) {
803803
_php_curl_verify_handlers(ch, /* reporterror */ true);
804-
zend_long retval_long = zval_get_long(&retval);
805-
if (retval_long == CURLKHMATCH_OK || retval_long == CURLKHMATCH_MISMATCH) {
806-
rval = retval_long;
804+
if (Z_TYPE(retval) == IS_LONG) {
805+
zend_long retval_long = zval_get_long(&retval);
806+
if (retval_long == CURLKHMATCH_OK || retval_long == CURLKHMATCH_MISMATCH) {
807+
rval = retval_long;
808+
} else {
809+
zend_throw_error(NULL, "The CURLOPT_SSH_HOSTKEYFUNCTION callback must return either CURLKHMATCH_OK or CURLKHMATCH_MISMATCH");
810+
}
807811
} else {
808-
zend_value_error("The CURLOPT_SSH_HOSTKEYFUNCTION callback must return either CURLKHMATCH_OK or CURLKHMATCH_MISMATCH");
812+
zend_type_error("The CURLOPT_SSH_HOSTKEYFUNCTION callback must return an integer");
809813
}
810-
} else {
811-
zend_value_error("The CURLOPT_SSH_HOSTKEYFUNCTION callback must return a return code");
812814
}
813815
zval_ptr_dtor(&argv[0]);
814816
zval_ptr_dtor(&argv[2]);

ext/curl/tests/curl_basic_027.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $host = curl_cli_server_start();
2121
$url = "{$host}/get.inc?test=";
2222
curl_setopt($ch, CURLOPT_URL, $url);
2323
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
24-
var_dump(curl_setopt($ch, CURLOPT_SSH_HOSTKEYFUNCTION, function ($keytype, $key, $keylen) {
24+
var_dump(curl_setopt($ch, CURLOPT_SSH_HOSTKEYFUNCTION, function ($ch, $keytype, $key, $keylen) {
2525
// Can't really trigger this in a test
2626
var_dump($keytype);
2727
var_dump($key);

0 commit comments

Comments
 (0)