From 334939324c20103bbf980e712421c468263d6504 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 6 Feb 2022 18:04:33 +0100 Subject: [PATCH] pattern: Fixed use-after-free when accessing arrays through an r-value --- lib/libimhex/include/hex/pattern_language/ast_node.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/include/hex/pattern_language/ast_node.hpp b/lib/libimhex/include/hex/pattern_language/ast_node.hpp index 535b0d1d8..6a913a48d 100644 --- a/lib/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast_node.hpp @@ -1556,7 +1556,14 @@ namespace hex::pl { explicit ASTNodeRValue(Path path) : ASTNode(), m_path(std::move(path)) { } - ASTNodeRValue(const ASTNodeRValue &) = default; + ASTNodeRValue(const ASTNodeRValue &other) { + for (auto &part : other.m_path) { + if (auto stringPart = std::get_if(&part); stringPart != nullptr) + this->m_path.push_back(*stringPart); + else if (auto nodePart = std::get_if(&part); nodePart != nullptr) + this->m_path.push_back((*nodePart)->clone()); + } + } ~ASTNodeRValue() override { for (auto &part : this->m_path) {