Commit 23ffb72a authored by Brad King's avatar Brad King
Browse files

cmake: Fix read-after-free while checking command-line arguments

Since commit v2.8.12~300^2~1 (CLI: Suppress the unused warning if the
key value pair is cached, 2013-05-16), cmake::SetCacheArgs saves a
cachedValue pointer and may cause the memory to be freed (by setting the
cache entry) before reading it again.  Fix this by saving the old value
in a separate string.
parent b041fc13
......@@ -343,16 +343,24 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
// The value is transformed if it is a filepath for example, so
// we can't compare whether the value is already in the cache until
// after we call AddCacheEntry.
const char *cachedValue =
bool haveValue = false;
std::string cachedValue;
if(const char *v = this->CacheManager->GetCacheValue(var))
haveValue = true;
cachedValue = v;
this->CacheManager->AddCacheEntry(var, value.c_str(),
"No help, variable specified on the command line.", type);
if (!cachedValue
|| strcmp(this->CacheManager->GetCacheValue(var),
cachedValue) != 0)
if (!haveValue ||
cachedValue != this->CacheManager->GetCacheValue(var))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment