iliaa Fri Mar 12 12:43:17 2004 EDT Modified files: (Branch: PHP_4_3) /php-src/ext/curl curl.c Log: MFH: Add checks of return values from user callback functions. http://cvs.php.net/diff.php/php-src/ext/curl/curl.c?r1=1.124.2.17&r2=1.124.2.18&ty=u Index: php-src/ext/curl/curl.c diff -u php-src/ext/curl/curl.c:1.124.2.17 php-src/ext/curl/curl.c:1.124.2.18 --- php-src/ext/curl/curl.c:1.124.2.17 Tue Mar 9 12:06:53 2004 +++ php-src/ext/curl/curl.c Fri Mar 12 12:43:17 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: curl.c,v 1.124.2.17 2004/03/09 17:06:53 rasmus Exp $ */ +/* $Id: curl.c,v 1.124.2.18 2004/03/12 17:43:17 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -368,6 +368,9 @@ length = -1; } else { + if (Z_TYPE_P(retval) != IS_LONG) { + convert_to_long_ex(&retval); + } length = Z_LVAL_P(retval); } @@ -400,7 +403,6 @@ case PHP_CURL_USER: { zval *argv[3]; zval *retval; - int length; int error; TSRMLS_FETCH(); @@ -422,11 +424,9 @@ if (error == FAILURE) { php_error(E_WARNING, "%s(): Cannot call the CURLOPT_READFUNCTION", get_active_function_name(TSRMLS_C)); - length = -1; - } - else { - memcpy(data, Z_STRVAL_P(retval), size * nmemb); - length = Z_STRLEN_P(retval); + } else if (Z_TYPE_P(retval) == IS_STRING) { + length = MIN(size * nmemb, Z_STRLEN_P(retval)); + memcpy(data, Z_STRVAL_P(retval), length); } zval_ptr_dtor(&argv[0]); @@ -485,6 +485,9 @@ length = -1; } else { + if (Z_TYPE_P(retval) != IS_LONG) { + convert_to_long_ex(&retval); + } length = Z_LVAL_P(retval); } zval_ptr_dtor(&argv[0]); @@ -492,8 +495,12 @@ zval_ptr_dtor(&retval); break; } + case PHP_CURL_IGNORE: return length; + + default: + return -1; } return length; } @@ -508,7 +515,7 @@ zval *argv[3]; zval *retval = NULL; int error; - int ret = 0; + int ret = -1; TSRMLS_FETCH(); MAKE_STD_ZVAL(argv[0]); @@ -526,17 +533,15 @@ retval, 2, argv TSRMLS_CC); if (error == FAILURE) { php_error(E_WARNING, "%s(): Couldn't call the CURLOPT_PASSWDFUNCTION", get_active_function_name(TSRMLS_C)); - ret = -1; - } - else { + } else if (Z_TYPE_P(retval) == IS_STRING) { if (Z_STRLEN_P(retval) > buflen) { php_error(E_WARNING, "%s(): Returned password is too long for libcurl to handle", get_active_function_name(TSRMLS_C)); - ret = -1; - } - else { - strlcpy(buf, Z_STRVAL_P(retval), buflen); + } else { + strlcpy(buf, Z_STRVAL_P(retval), Z_STRLEN_P(retval)); } + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "User handler '%s' did not return a string.", Z_STRVAL_P(func)); } zval_ptr_dtor(&argv[0]);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php