Skip to content

Commit

Permalink
Fixed use after free in ModSecurity::processContentOffset
Browse files Browse the repository at this point in the history
- Use after free issue detected with Address Sanitizer while running
  the reading_logs_with_offset example.
- Keeps reference to last element in vars vector with vars.back(). Then
  it removes the element from vars calling vars.pop_back() which
  invalidates the reference, but it's accessed later in the function.
  - Fixed by copying the value instead.
  • Loading branch information
eduar-hte committed Apr 25, 2024
1 parent fc68a23 commit 7cb67b0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/modsecurity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
std::string value;
yajl_gen_map_open(g);
vars.pop_back();
const std::string &startingAt = vars.back().str();
const std::string startingAt = vars.back().str();
vars.pop_back();
const std::string &size = vars.back().str();
const std::string size = vars.back().str();
vars.pop_back();
yajl_gen_string(g,
reinterpret_cast<const unsigned char*>("startingAt"),
Expand Down Expand Up @@ -346,9 +346,9 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
strlen("highlight"));
yajl_gen_map_open(g);
ops.pop_back();
std::string startingAt = ops.back().str();
const std::string startingAt = ops.back().str();
ops.pop_back();
std::string size = ops.back().str();
const std::string size = ops.back().str();
ops.pop_back();
yajl_gen_string(g,
reinterpret_cast<const unsigned char*>("startingAt"),
Expand Down

0 comments on commit 7cb67b0

Please sign in to comment.