Skip to content

Commit

Permalink
Merge #2695: [CLI][Build] Guard libevent error messages
Browse files Browse the repository at this point in the history
3570941 [CLI] Guard libevent error messages (Fuzzbawls)

Pull request description:

  The error message enum `evhttp_request_error` was introduced in libevent
  2.1.3, which we do not necessarily require, and is not available to some
  older but still supported linux distros (namely Ubuntu Xenial 16.04
  LTS).

  Add a version guard to maintain compatibility with the 2.0.x branch of
  libevent.

ACKs for top commit:
  random-zebra:
    utACK 3570941
  furszy:
    utACK 3570941

Tree-SHA512: c8914bb5e049eca8006c56eebcadb554594becd54c69a16becfb70505958f2ae998cc8a24b57340bdf8ea97f2c6637704512b9e796d098c9bb817b63fdc1b44c
  • Loading branch information
furszy committed Dec 26, 2021
2 parents 38cbb3b + 3570941 commit 2d37006
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pivx-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct HTTPReply
const char *http_errorstring(int code)
{
switch(code) {
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
case EVREQ_HTTP_TIMEOUT:
return "timeout reached";
case EVREQ_HTTP_EOF:
Expand All @@ -152,6 +153,7 @@ const char *http_errorstring(int code)
return "request was canceled";
case EVREQ_HTTP_DATA_TOO_LONG:
return "response body is larger than allowed";
#endif
default:
return "unknown";
}
Expand Down Expand Up @@ -182,11 +184,13 @@ static void http_request_done(struct evhttp_request *req, void *ctx)
}
}

#if LIBEVENT_VERSION_NUMBER >= 0x02010300
static void http_error_cb(enum evhttp_request_error err, void *ctx)
{
HTTPReply *reply = static_cast<HTTPReply*>(ctx);
reply->error = err;
}
#endif

UniValue CallRPC(const std::string& strMethod, const UniValue& params)
{
Expand All @@ -204,7 +208,9 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);
if (req == NULL)
throw std::runtime_error("create http request failed");
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
evhttp_request_set_error_cb(req.get(), http_error_cb);
#endif

// Get credentials
std::string strRPCUserColonPass;
Expand Down

0 comments on commit 2d37006

Please sign in to comment.