Skip to content

Commit 5025eb0

Browse files
jaynikic
authored andcommitted
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]: curl/curl#3629
1 parent 006355c commit 5025eb0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/curl/interface.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,8 +3310,12 @@ PHP_FUNCTION(curl_error)
33103310
RETURN_FALSE;
33113311
}
33123312

3313-
ch->err.str[CURL_ERROR_SIZE] = 0;
3314-
RETURN_STRING(ch->err.str);
3313+
if (ch->err.no) {
3314+
ch->err.str[CURL_ERROR_SIZE] = 0;
3315+
RETURN_STRING(ch->err.str);
3316+
} else {
3317+
RETURN_EMPTY_STRING();
3318+
}
33153319
}
33163320
/* }}} */
33173321

0 commit comments

Comments
 (0)