Fixed crashes in the SSL HTTP connection.

This commit is contained in:
madmaxoft
2014-05-01 15:08:15 +02:00
parent dc2d2ce53c
commit 60850fe3e8
9 changed files with 36 additions and 23 deletions
+7 -7
View File
@@ -145,7 +145,7 @@ void cHTTPConnection::Terminate(void)
void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
bool cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
{
switch (m_State)
{
@@ -163,12 +163,12 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
m_CurrentRequest = NULL;
m_State = wcsInvalid;
m_HTTPServer.CloseConnection(*this);
return;
return true;
}
if (m_CurrentRequest->IsInHeaders())
{
// The request headers are not yet complete
return;
return false;
}
// The request has finished parsing its headers successfully, notify of it:
@@ -184,13 +184,12 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
// Process the rest of the incoming data into the request body:
if (a_Size > BytesConsumed)
{
cHTTPConnection::DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed);
return cHTTPConnection::DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed);
}
else
{
cHTTPConnection::DataReceived("", 0); // If the request has zero body length, let it be processed right-away
return cHTTPConnection::DataReceived("", 0); // If the request has zero body length, let it be processed right-away
}
break;
}
case wcsRecvBody:
@@ -210,7 +209,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
{
m_State = wcsInvalid;
m_HTTPServer.CloseConnection(*this);
return;
return true;
}
delete m_CurrentRequest;
m_CurrentRequest = NULL;
@@ -224,6 +223,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
break;
}
}
return false;
}
+9 -3
View File
@@ -91,9 +91,15 @@ protected:
// cSocketThreads::cCallback overrides:
virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
virtual void SocketClosed (void) override; // The socket has been closed for any reason
/** Data is received from the client.
Returns true if the connection has been closed as the result of parsing the data. */
virtual bool DataReceived(const char * a_Data, size_t a_Size) override;
/** Data can be sent to client */
virtual void GetOutgoingData(AString & a_Data) override;
/** The socket has been closed for any reason */
virtual void SocketClosed(void) override;
} ;
typedef std::vector<cHTTPConnection *> cHTTPConnections;
+7 -3
View File
@@ -25,7 +25,7 @@ cSslHTTPConnection::cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509Ce
void cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
bool cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
{
// If there is outgoing data in the queue, notify the server that it should write it out:
if (!m_OutgoingData.empty())
@@ -52,13 +52,17 @@ void cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
int NumRead = m_Ssl.ReadPlain(Buffer, sizeof(Buffer));
if (NumRead > 0)
{
super::DataReceived(Buffer, (size_t)NumRead);
if (super::DataReceived(Buffer, (size_t)NumRead))
{
// The socket has been closed, and the object is already deleted. Bail out.
return true;
}
}
// If both failed, bail out:
if ((BytesWritten == 0) && (NumRead <= 0))
{
return;
return false;
}
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ protected:
cPublicKeyPtr m_PrivateKey;
// cHTTPConnection overrides:
virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
virtual bool DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
} ;