Skip to content

Buffer overflow and Crash due to non-'\0' ended string. #360

@spwlyzx

Description

@spwlyzx

What is the point of (seeming deliberately) converting 2 std::string variables to type std::vector<char>, which strips their ending '\0', before passing them to an API which REQUIRES strings are ended with '\0'?

This crashes my code due to buffer read overflow.

My fix is as follows. Is it correct?

--- a/backward.hpp
+++ b/backward.hpp
@@ -1,4 +1,4 @@
-/*
+/*
  * backward.hpp
  * Copyright 2013 Google Inc. All Rights Reserved.
  *
@@ -3627,9 +3627,7 @@ public:
     ret.image_name = temp;
     GetModuleBaseNameA(process, module, temp, sizeof(temp));
     ret.module_name = temp;
-    std::vector<char> img(ret.image_name.begin(), ret.image_name.end());
-    std::vector<char> mod(ret.module_name.begin(), ret.module_name.end());
-    SymLoadModule64(process, 0, &img[0], &mod[0], (DWORD64)ret.base_address,
+    SymLoadModule64(process, 0, ret.image_name.c_str(), ret.module_name.c_str(), (DWORD64)ret.base_address,
                     ret.load_size);
     return ret;
   }

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