]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- improved error reporting 1160/head
authorArvin Schnell <aschnell@suse.de>
Wed, 24 Jun 2026 08:43:13 +0000 (10:43 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 24 Jun 2026 08:43:13 +0000 (10:43 +0200)
stomp/Stomp.cc
stomp/testsuite/read1.cc

index a10576e10ecac0f68502bb03ba18717f1ba7bf74..1a3e3ee55b1eeb7e3c9675b6903777a9df98308a 100644 (file)
@@ -111,13 +111,16 @@ namespace Stomp
                        {
                            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
index a6720a57cbcf65de8e63e45787cbbc47b05672c6..45cfc84aa4e3396c3625b1d9cbfa01d94dfc0b15 100644 (file)
@@ -105,6 +105,32 @@ BOOST_AUTO_TEST_CASE(error1)
 
 
 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
 
@@ -112,13 +138,12 @@ BOOST_AUTO_TEST_CASE(error2)
     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
 
@@ -126,13 +151,12 @@ BOOST_AUTO_TEST_CASE(error3)
     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