summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Noetzli <andres.noetzli@gmail.com>2020-07-17 15:25:54 -0700
committerGitHub <noreply@github.com>2020-07-17 15:25:54 -0700
commit8f085eb6a087242ab8c775ec4fe41ab9a194cec2 (patch)
treeb21935259add8fdbfca57bf4fdd1a76ea96985d9
parentf99889b0c1260fccf28daac995e58312912bae9f (diff)
Add NodeManagerScopes to fix use-after-free issues (#4768)
This commit fixes our current ASan issues. Some methods in `NodeManager` were not creating a `NodeManagerScope` for `this` but were indirectly calling methods that get the `NodeManager` from the current scope, so we ended up calling methods on a `NodeManager` that had already been destroyed.
-rw-r--r--src/expr/node_manager.cpp4
-rw-r--r--src/expr/node_manager.h3
2 files changed, 7 insertions, 0 deletions
diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp
index c68b0df86..e9f56bf3f 100644
--- a/src/expr/node_manager.cpp
+++ b/src/expr/node_manager.cpp
@@ -106,6 +106,10 @@ NodeManager::NodeManager(ExprManager* exprManager)
}
void NodeManager::init() {
+ // `mkConst()` indirectly needs the correct NodeManager in scope because we
+ // call `NodeValue::inc()` which uses `NodeManager::curentNM()`
+ NodeManagerScope nms(this);
+
poolInsert( &expr::NodeValue::null() );
for(unsigned i = 0; i < unsigned(kind::LAST_KIND); ++i) {
diff --git a/src/expr/node_manager.h b/src/expr/node_manager.h
index 1a28a16eb..84c4b44e0 100644
--- a/src/expr/node_manager.h
+++ b/src/expr/node_manager.h
@@ -1484,6 +1484,9 @@ TypeNode NodeManager::mkTypeConst(const T& val) {
template <class NodeClass, class T>
NodeClass NodeManager::mkConstInternal(const T& val) {
+ // This method indirectly calls `NodeValue::inc()`, which relies on having
+ // the correct `NodeManager` in scope.
+ NodeManagerScope nms(this);
// typedef typename kind::metakind::constantMap<T>::OwningTheory theory_t;
NVStorage<1> nvStorage;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback