summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2020-12-05 22:38:12 (GMT)
committerCraig Scott <craig.scott@crascit.com>2020-12-05 22:38:12 (GMT)
commitab1ee5aab81c105d788405c1c0800edc96437843 (patch)
treeda517cc8718c1dd8835d14351c47c058cdc50b34
parent14576a40accb93f0f0a7f06b00996edf17ba4aa2 (diff)
downloadCMake-ab1ee5aab81c105d788405c1c0800edc96437843.zip
CMake-ab1ee5aab81c105d788405c1c0800edc96437843.tar.gz
CMake-ab1ee5aab81c105d788405c1c0800edc96437843.tar.bz2
get_directory_property: Check for empty or missing property name
Fixes: #21555
-rw-r--r--Source/cmGetDirectoryPropertyCommand.cxx43
-rw-r--r--Tests/RunCMake/get_property/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_empty-result.txt1
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_empty-stderr.txt4
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_empty.cmake1
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_missing-result.txt1
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_missing-stderr.txt4
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_missing.cmake1
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_missingWithDir-result.txt1
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_missingWithDir-stderr.txt4
-rw-r--r--Tests/RunCMake/get_property/get_directory_property_missingWithDir.cmake1
11 files changed, 46 insertions, 18 deletions
diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx
index c2098c0..7fbd479 100644
--- a/Source/cmGetDirectoryPropertyCommand.cxx
+++ b/Source/cmGetDirectoryPropertyCommand.cxx
@@ -50,6 +50,10 @@ bool cmGetDirectoryPropertyCommand(std::vector<std::string> const& args,
return false;
}
++i;
+ if (i == args.end()) {
+ status.SetError("called with incorrect number of arguments");
+ return false;
+ }
}
// OK, now we have the directory to process, we just get the requested
@@ -67,27 +71,30 @@ bool cmGetDirectoryPropertyCommand(std::vector<std::string> const& args,
return true;
}
+ if (i->empty()) {
+ status.SetError("given empty string for the property name to get");
+ return false;
+ }
+
const char* prop = nullptr;
- if (!i->empty()) {
- if (*i == "DEFINITIONS") {
- switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0059)) {
- case cmPolicies::WARN:
- status.GetMakefile().IssueMessage(
- MessageType::AUTHOR_WARNING,
- cmPolicies::GetPolicyWarning(cmPolicies::CMP0059));
- CM_FALLTHROUGH;
- case cmPolicies::OLD:
- StoreResult(status.GetMakefile(), variable,
- status.GetMakefile().GetDefineFlagsCMP0059());
- return true;
- case cmPolicies::NEW:
- case cmPolicies::REQUIRED_ALWAYS:
- case cmPolicies::REQUIRED_IF_USED:
- break;
- }
+ if (*i == "DEFINITIONS") {
+ switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0059)) {
+ case cmPolicies::WARN:
+ status.GetMakefile().IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0059));
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ StoreResult(status.GetMakefile(), variable,
+ status.GetMakefile().GetDefineFlagsCMP0059());
+ return true;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ break;
}
- prop = cmToCStr(dir->GetProperty(*i));
}
+ prop = cmToCStr(dir->GetProperty(*i));
StoreResult(status.GetMakefile(), variable, prop);
return true;
}
diff --git a/Tests/RunCMake/get_property/RunCMakeTest.cmake b/Tests/RunCMake/get_property/RunCMakeTest.cmake
index c4ee53d..2143fa2 100644
--- a/Tests/RunCMake/get_property/RunCMakeTest.cmake
+++ b/Tests/RunCMake/get_property/RunCMakeTest.cmake
@@ -2,6 +2,9 @@ include(RunCMake)
run_cmake(cache_properties)
run_cmake(directory_properties)
+run_cmake(get_directory_property_empty)
+run_cmake(get_directory_property_missing)
+run_cmake(get_directory_property_missingWithDir)
run_cmake(global_properties)
run_cmake(install_properties)
run_cmake(source_properties)
diff --git a/Tests/RunCMake/get_property/get_directory_property_empty-result.txt b/Tests/RunCMake/get_property/get_directory_property_empty-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_empty-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/get_property/get_directory_property_empty-stderr.txt b/Tests/RunCMake/get_property/get_directory_property_empty-stderr.txt
new file mode 100644
index 0000000..baa73f3
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_empty-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at get_directory_property_empty.cmake:1 \(get_directory_property\):
+ get_directory_property given empty string for the property name to get
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/get_property/get_directory_property_empty.cmake b/Tests/RunCMake/get_property/get_directory_property_empty.cmake
new file mode 100644
index 0000000..b49be1c
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_empty.cmake
@@ -0,0 +1 @@
+get_directory_property(outVar "")
diff --git a/Tests/RunCMake/get_property/get_directory_property_missing-result.txt b/Tests/RunCMake/get_property/get_directory_property_missing-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_missing-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/get_property/get_directory_property_missing-stderr.txt b/Tests/RunCMake/get_property/get_directory_property_missing-stderr.txt
new file mode 100644
index 0000000..e101c76
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_missing-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at get_directory_property_missing.cmake:1 \(get_directory_property\):
+ get_directory_property called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/get_property/get_directory_property_missing.cmake b/Tests/RunCMake/get_property/get_directory_property_missing.cmake
new file mode 100644
index 0000000..c28157e
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_missing.cmake
@@ -0,0 +1 @@
+get_directory_property(outVar)
diff --git a/Tests/RunCMake/get_property/get_directory_property_missingWithDir-result.txt b/Tests/RunCMake/get_property/get_directory_property_missingWithDir-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_missingWithDir-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/get_property/get_directory_property_missingWithDir-stderr.txt b/Tests/RunCMake/get_property/get_directory_property_missingWithDir-stderr.txt
new file mode 100644
index 0000000..66deabb
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_missingWithDir-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at get_directory_property_missingWithDir.cmake:1 \(get_directory_property\):
+ get_directory_property called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/get_property/get_directory_property_missingWithDir.cmake b/Tests/RunCMake/get_property/get_directory_property_missingWithDir.cmake
new file mode 100644
index 0000000..573e14a
--- /dev/null
+++ b/Tests/RunCMake/get_property/get_directory_property_missingWithDir.cmake
@@ -0,0 +1 @@
+get_directory_property(outVar DIRECTORY .)