Skip to content

Commit

Permalink
Fix out-of-bound vector access in Regex compiler
Browse files Browse the repository at this point in the history
Summary: This out-of-bound access is likely harmless. However, the test hits an assertion failure and crashes in debug builds on Windows. The problem is that we could be calling `operator[]()` with one past the last valid element.

Reviewed By: tmikov

Differential Revision: D17085369

fbshipit-source-id: 3d82640332a62672c053702ea3956eac8ce230c8
  • Loading branch information
haozhun authored and facebook-github-bot committed Aug 28, 2019
1 parent 0acbae8 commit cf95acb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/hermes/Regex/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,9 @@ void Node::optimizeNodeList(NodeList &nodes, constants::SyntaxFlags flags) {
unique_ptr<MatchCharNode>(new MatchCharNode(std::move(chars), icase));
// Fill the remainder of the range with null (we'll clean them up after
// the loop) and skip to the end of the range.
std::fill(&nodes[rangeStart + 1], &nodes[rangeEnd], nullptr);
// Note that rangeEnd may be one past the last valid element.
std::fill(
nodes.begin() + (rangeStart + 1), nodes.begin() + rangeEnd, nullptr);
idx = rangeEnd - 1;
}
}
Expand Down

0 comments on commit cf95acb

Please sign in to comment.