{
vector<char> buf(content_length);
is.read(buf.data(), content_length);
+ if (!is)
+ throw runtime_error("stomp error: premature end of body");
+
msg.body.assign(buf.data(), content_length);
}
// still read the \0 that terminates the frame
char buf2 = '-';
is.read(&buf2, 1);
- if (buf2 != '\0')
+ if (!is || buf2 != '\0')
throw runtime_error("stomp error: missing \\0 at frame end");
}
else
BOOST_AUTO_TEST_CASE(error2)
+{
+ // missing \0 at frame end
+
+ istringstream s1("HELLO\nkey:value\ncontent-length:5\n\nWORLD");
+ istream s2(s1.rdbuf());
+
+ BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
+ return strcmp(e.what(), "stomp error: missing \\0 at frame end") == 0;
+ });
+}
+
+
+BOOST_AUTO_TEST_CASE(error3)
+{
+ // truncated body
+
+ istringstream s1("HELLO\nkey:value\ncontent-length:50000\n\nWORLD" + null);
+ istream s2(s1.rdbuf());
+
+ BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
+ return strcmp(e.what(), "stomp error: premature end of body") == 0;
+ });
+}
+
+
+BOOST_AUTO_TEST_CASE(error4)
{
// empty content-lenght value
istream s2(s1.rdbuf());
BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
- cout << e.what() << '\n';
return strcmp(e.what(), "stomp error: invalid content-length syntax ''") == 0;
});
}
-BOOST_AUTO_TEST_CASE(error3)
+BOOST_AUTO_TEST_CASE(error5)
{
// invalid content-lenght value
istream s2(s1.rdbuf());
BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
- cout << e.what() << '\n';
return strcmp(e.what(), "stomp error: invalid content-length value '5a'") == 0;
});
}
-BOOST_AUTO_TEST_CASE(error4)
+BOOST_AUTO_TEST_CASE(error6)
{
// invalid negative content-lenght value