Livestatus: Fix crash when socket exception is thrown during query reponse.

Fixes #4619
This commit is contained in:
Michael Friedrich 2013-11-06 18:54:01 +01:00
parent c48bb9c3dc
commit 686446584c
1 changed files with 18 additions and 3 deletions

View File

@ -477,8 +477,16 @@ void Query::SendResponse(const Stream::Ptr& stream, int code, const String& data
if (m_ResponseHeader == "fixed16")
PrintFixed16(stream, code, data);
if (m_ResponseHeader == "fixed16" || code == LivestatusErrorOK)
if (m_ResponseHeader == "fixed16" || code == LivestatusErrorOK) {
try {
stream->Write(data.CStr(), data.GetLength());
} catch (const std::exception& ex) {
std::ostringstream info;
info << "Exception thrown while writing to the livestatus socket: " << std::endl
<< boost::diagnostic_information(ex);
Log(LogCritical, "livestatus", info.str());
}
}
}
void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data)
@ -490,7 +498,14 @@ void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data
String header = sCode + String(16 - 3 - sLength.GetLength() - 1, ' ') + sLength + m_Separators[0];
try {
stream->Write(header.CStr(), header.GetLength());
} catch (const std::exception& ex) {
std::ostringstream info;
info << "Exception thrown while writing to the livestatus socket: " << std::endl
<< boost::diagnostic_information(ex);
Log(LogCritical, "livestatus", info.str());
}
}
bool Query::Execute(const Stream::Ptr& stream)