mirror of https://github.com/Icinga/icinga2.git
Fix null ptr dereference in HttpServerConnection::ProcessMessageAsync
This commit is contained in:
parent
6d01808adf
commit
a4a73fa67c
|
@ -26,7 +26,7 @@
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
HttpResponse::HttpResponse(Stream::Ptr stream, const HttpRequest& request)
|
HttpResponse::HttpResponse(Stream::Ptr stream, const HttpRequest& request)
|
||||||
: Complete(false), m_State(HttpResponseStart), m_Request(request), m_Stream(std::move(stream))
|
: Complete(false), m_State(HttpResponseStart), m_Request(&request), m_Stream(std::move(stream))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void HttpResponse::SetStatus(int code, const String& message)
|
void HttpResponse::SetStatus(int code, const String& message)
|
||||||
|
@ -41,7 +41,7 @@ void HttpResponse::SetStatus(int code, const String& message)
|
||||||
|
|
||||||
String status = "HTTP/";
|
String status = "HTTP/";
|
||||||
|
|
||||||
if (m_Request.ProtocolVersion == HttpVersion10)
|
if (m_Request->ProtocolVersion == HttpVersion10)
|
||||||
status += "1.0";
|
status += "1.0";
|
||||||
else
|
else
|
||||||
status += "1.1";
|
status += "1.1";
|
||||||
|
@ -61,7 +61,7 @@ void HttpResponse::AddHeader(const String& key, const String& value)
|
||||||
void HttpResponse::FinishHeaders()
|
void HttpResponse::FinishHeaders()
|
||||||
{
|
{
|
||||||
if (m_State == HttpResponseHeaders) {
|
if (m_State == HttpResponseHeaders) {
|
||||||
if (m_Request.ProtocolVersion == HttpVersion11)
|
if (m_Request->ProtocolVersion == HttpVersion11)
|
||||||
AddHeader("Transfer-Encoding", "chunked");
|
AddHeader("Transfer-Encoding", "chunked");
|
||||||
|
|
||||||
AddHeader("Server", "Icinga/" + Application::GetAppVersion());
|
AddHeader("Server", "Icinga/" + Application::GetAppVersion());
|
||||||
|
@ -78,7 +78,7 @@ void HttpResponse::WriteBody(const char *data, size_t count)
|
||||||
{
|
{
|
||||||
ASSERT(m_State == HttpResponseHeaders || m_State == HttpResponseBody);
|
ASSERT(m_State == HttpResponseHeaders || m_State == HttpResponseBody);
|
||||||
|
|
||||||
if (m_Request.ProtocolVersion == HttpVersion10) {
|
if (m_Request->ProtocolVersion == HttpVersion10) {
|
||||||
if (!m_Body)
|
if (!m_Body)
|
||||||
m_Body = new FIFO();
|
m_Body = new FIFO();
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ void HttpResponse::Finish()
|
||||||
{
|
{
|
||||||
ASSERT(m_State != HttpResponseEnd);
|
ASSERT(m_State != HttpResponseEnd);
|
||||||
|
|
||||||
if (m_Request.ProtocolVersion == HttpVersion10) {
|
if (m_Request->ProtocolVersion == HttpVersion10) {
|
||||||
if (m_Body)
|
if (m_Body)
|
||||||
AddHeader("Content-Length", Convert::ToString(m_Body->GetAvailableBytes()));
|
AddHeader("Content-Length", Convert::ToString(m_Body->GetAvailableBytes()));
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ void HttpResponse::Finish()
|
||||||
|
|
||||||
m_State = HttpResponseEnd;
|
m_State = HttpResponseEnd;
|
||||||
|
|
||||||
if (m_Request.ProtocolVersion == HttpVersion10 || m_Request.Headers->Get("connection") == "close")
|
if (m_Request->ProtocolVersion == HttpVersion10 || m_Request->Headers->Get("connection") == "close")
|
||||||
m_Stream->Shutdown();
|
m_Stream->Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,3 +263,8 @@ bool HttpResponse::IsPeerConnected() const
|
||||||
{
|
{
|
||||||
return !m_Stream->IsEof();
|
return !m_Stream->IsEof();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpResponse::RebindRequest(const HttpRequest& request)
|
||||||
|
{
|
||||||
|
m_Request = &request;
|
||||||
|
}
|
||||||
|
|
|
@ -65,10 +65,12 @@ public:
|
||||||
|
|
||||||
bool IsPeerConnected() const;
|
bool IsPeerConnected() const;
|
||||||
|
|
||||||
|
void RebindRequest(const HttpRequest& request);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HttpResponseState m_State;
|
HttpResponseState m_State;
|
||||||
std::shared_ptr<ChunkReadContext> m_ChunkContext;
|
std::shared_ptr<ChunkReadContext> m_ChunkContext;
|
||||||
const HttpRequest& m_Request;
|
const HttpRequest *m_Request;
|
||||||
Stream::Ptr m_Stream;
|
Stream::Ptr m_Stream;
|
||||||
FIFO::Ptr m_Body;
|
FIFO::Ptr m_Body;
|
||||||
std::vector<String> m_Headers;
|
std::vector<String> m_Headers;
|
||||||
|
|
|
@ -316,6 +316,8 @@ bool HttpServerConnection::ManageHeaders(HttpResponse& response)
|
||||||
|
|
||||||
void HttpServerConnection::ProcessMessageAsync(HttpRequest& request, HttpResponse& response, const ApiUser::Ptr& user)
|
void HttpServerConnection::ProcessMessageAsync(HttpRequest& request, HttpResponse& response, const ApiUser::Ptr& user)
|
||||||
{
|
{
|
||||||
|
response.RebindRequest(request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpHandler::ProcessRequest(user, request, response);
|
HttpHandler::ProcessRequest(user, request, response);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
|
|
Loading…
Reference in New Issue