summaryrefslogtreecommitdiffstats
path: root/Source/cmVariableWatch.cxx
diff options
context:
space:
mode:
authorYves Frederix <yves.frederix@gmail.com>2016-03-23 09:37:51 (GMT)
committerBrad King <brad.king@kitware.com>2016-03-23 20:17:36 (GMT)
commitc61040282557ba268e144ffa5e2d1935b5991d8d (patch)
tree4f0784d71e26cf1722fc261258f4a343c5530021 /Source/cmVariableWatch.cxx
parentb369959eb55dbea601315530185cb480c922cc77 (diff)
downloadCMake-c61040282557ba268e144ffa5e2d1935b5991d8d.zip
CMake-c61040282557ba268e144ffa5e2d1935b5991d8d.tar.gz
CMake-c61040282557ba268e144ffa5e2d1935b5991d8d.tar.bz2
Avoid occasional use-after-free when a variable watch is executed
Re-lookup a variable value when an associated VariableWatch is executed in cmMakefile::GetDefinition. This fixes a problem with 'def' sometimes becoming invalid due to memory reallocation inside an std::vector. In this case, the problem was that if the call to VariableAccessed actually executed a callback function, the internal state of the makefile has changed due to the associated function scope being pushed. This in turn implies that a new cmDefinitions instance was pushed in cmMakefile::VarTree. As cmLinkedTree is based on an std::vector, this push can have triggered reallocation of its internal memory buffer. However, as the value of 'def', which was computed on method entry, actually points to a property of one of the cmDefinitions instances in cmMakefile::VarTree, reallocation can invalidate the value of 'def' so that it cannot simply be returned at the end of the function. The solution implemented here is to simply lookup the value of 'def' again.
Diffstat (limited to 'Source/cmVariableWatch.cxx')
-rw-r--r--Source/cmVariableWatch.cxx4
1 files changed, 3 insertions, 1 deletions
diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx
index 57dde31..a200718 100644
--- a/Source/cmVariableWatch.cxx
+++ b/Source/cmVariableWatch.cxx
@@ -96,7 +96,7 @@ void cmVariableWatch::RemoveWatch(const std::string& variable,
}
}
-void cmVariableWatch::VariableAccessed(const std::string& variable,
+bool cmVariableWatch::VariableAccessed(const std::string& variable,
int access_type,
const char* newValue,
const cmMakefile* mf) const
@@ -112,5 +112,7 @@ void cmVariableWatch::VariableAccessed(const std::string& variable,
(*it)->Method(variable, access_type, (*it)->ClientData,
newValue, mf);
}
+ return true;
}
+ return false;
}