Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseSignals should fail if frame data length is too small #29

Open
TheWhiteBug opened this issue May 15, 2024 · 0 comments
Open

parseSignals should fail if frame data length is too small #29

TheWhiteBug opened this issue May 15, 2024 · 0 comments

Comments

@TheWhiteBug
Copy link

TheWhiteBug commented May 15, 2024

Hello. Doing some test I got what I consider unexpected results as I was sending incomplete frames; i.e. frames where the data buffer was not large enough to actually contain signal data..

Here is a draft of a patch I would like you to consider. Not certain if the check is correct but it does appear to "patch" the issue, preventing unexpected parsing success. I certainly would like to have your point of view on this.

dbc_parser_cpp$ git diff | sed 's/^M//g'
diff --git a/include/libdbc/message.hpp b/include/libdbc/message.hpp
index e903fed..b31b960 100644
--- a/include/libdbc/message.hpp
+++ b/include/libdbc/message.hpp
@@ -19,6 +19,7 @@ struct Message {
                ErrorBigEndian,
                ErrorUnknownID,
                ErrorInvalidConversion,
+               ErrorMessageTooShort, // or something...
        };

        /*!
diff --git a/src/message.cpp b/src/message.cpp
index 443526a..97233c0 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -31,6 +31,8 @@ Message::ParseSignalsStatus Message::parseSignals(const std::vector<uint8_t>& da
        const auto len = size * 8;
        uint64_t v = 0;
        for (const auto& signal : m_signals) {
+               if (signal.size > len)
+                       return ParseSignalsStatus::ErrorMessageTooShort;
                if (signal.is_bigendian) {
                        uint32_t start_bit = 8 * (signal.start_bit / 8) + (7 - (signal.start_bit % 8)); // Calculation taken from python CAN
                        v = data_big_endian << start_bit;
@TheWhiteBug TheWhiteBug changed the title parseSignals should fail if frame data lenght is to small parseSignals should fail if frame data lenght is too small May 15, 2024
@LinuxDevon LinuxDevon changed the title parseSignals should fail if frame data lenght is too small parseSignals should fail if frame data length is too small May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant