Skip to content

Commit

Permalink
curl_error: return an empty string if no error occurred
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jay authored and nikic committed Mar 1, 2019
1 parent 006355c commit 5025eb0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
/* }}} */

Expand Down

0 comments on commit 5025eb0

Please sign in to comment.