Skip to content

Segfault in lsbom #33

@cluck

Description

@cluck

Thank you for this great utility!

Unfortunately, commit 704739c introduced a segfault in lsbom, which is triggered verifying any Bom. Even the provided docker image fails to build.

I resolved the issue as follows:

diff --git a/src/lsbom.cpp b/src/lsbom.cpp
index 22d51e7..94fbb90 100644
--- a/src/lsbom.cpp
+++ b/src/lsbom.cpp
@@ -268,7 +268,7 @@ int main(int argc, char *argv[]) {

       DEBUG(2, "BOMVar 0x" << hex << ntohl(var->index) << ' ' << name << ':');

-      if (strstr(name.c_str(),"Paths") == 0) {
+      if (name.rfind("Paths", 0) == 0) {
         BOMPaths *paths = (BOMPaths *)lookup(tree->child);

         typedef map<uint32_t, string> filenames_t;

Passing c_str() pointers to standard library string functions is problematic; the C++ reference says the pointer obtained from c_str() may be invalidated by passing a non-const reference to the string to any standard library function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions