Don't crash when the deserialization of an error message fails

Found while scanning the code of an
open source project related to onions.
This commit is contained in:
Thomas Jarosch 2015-01-17 15:56:09 +01:00
parent 193645318b
commit 36bcefc39d
2 changed files with 9 additions and 0 deletions

View File

@ -148,6 +148,9 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
break;
}
if (results.size() != 4)
throw InternalError(0, "Internal Error: Deserialization of error message failed");
_id = results[0];
_severity = Severity::fromString(results[1]);
_shortMessage = results[2];

View File

@ -53,6 +53,7 @@ private:
// Serialize / Deserialize inconclusive message
TEST_CASE(SerializeInconclusiveMessage);
TEST_CASE(DeserializeInvalidInput);
TEST_CASE(suppressUnmatchedSuppressions);
}
@ -260,6 +261,11 @@ private:
ASSERT_EQUALS("Programming error", msg2.verboseMessage());
}
void DeserializeInvalidInput() const {
ErrorMessage msg;
ASSERT_THROW(msg.deserialize("500foobar"), InternalError);
}
void suppressUnmatchedSuppressions() {
std::list<Suppressions::SuppressionEntry> suppressions;