From 5025eb05bde83a0a51eb0668c45c240b366545bf Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Fri, 1 Mar 2019 01:37:00 -0500 Subject: [PATCH] curl_error: return an empty string if no error occurred CURLOPT_ERRORBUFFER doc says "Do not rely on the contents of the buffer unless an error code was returned." [1] Prior to this change the error buffer was returned even if no error had occurred, and that buffer may contain incorrect information in such a case. [2] [1]: https://curl.haxx.se/libcurl/c/CURLOPT_ERRORBUFFER.html [2]: https://github.com/curl/curl/issues/3629 --- ext/curl/interface.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 3af7ec12e23c..a252bb3a219d 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -3310,8 +3310,12 @@ PHP_FUNCTION(curl_error) RETURN_FALSE; } - ch->err.str[CURL_ERROR_SIZE] = 0; - RETURN_STRING(ch->err.str); + if (ch->err.no) { + ch->err.str[CURL_ERROR_SIZE] = 0; + RETURN_STRING(ch->err.str); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */