summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2018-07-20 01:20:18 +0000
committerJim Ingham <jingham@apple.com>2018-07-20 01:20:18 +0000
commite5ba124379636935c36ad36019f581d9366d0833 (patch)
treeb4a69f9b8fe2897fdb56c7c194029e2de5dbd95c
parent17e89d27ec0dcbf2e63ad9ad03c0ab4870a702c7 (diff)
Defend LoadImageUsingPaths against a path list
with empty paths on it. git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@337515 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py21
-rw-r--r--source/Plugins/Platform/POSIX/PlatformPOSIX.cpp4
2 files changed, 23 insertions, 2 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py b/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
index ba85039be..2050586ad 100644
--- a/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
+++ b/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
@@ -103,10 +103,27 @@ class LoadUsingPathsTestCase(TestBase):
out_spec = lldb.SBFileSpec()
token = process.LoadImageUsingPaths(relative_spec, paths, out_spec, error)
- self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
- self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")
+ self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token with relative path")
+ self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library with relative path")
process.UnloadImage(token)
+
+ # Make sure the presence of an empty path doesn't mess anything up:
+ paths.Clear()
+ paths.AppendString("")
+ paths.AppendString(os.path.join(self.wd, "no_such_dir"))
+ paths.AppendString(self.wd)
+ relative_spec = lldb.SBFileSpec(os.path.join("hidden", self.lib_name))
+
+ out_spec = lldb.SBFileSpec()
+ token = process.LoadImageUsingPaths(relative_spec, paths, out_spec, error)
+
+ self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token with included empty path")
+ self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library with included empty path")
+
+ process.UnloadImage(token)
+
+
# Finally, passing in an absolute path should work like the basename:
# This should NOT work because we've taken hidden_dir off the paths:
diff --git a/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index 16934bed8..5e7ffe719 100644
--- a/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -1155,6 +1155,10 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process,
size_t buffer_size = 0;
std::string path_array;
for (auto path : *paths) {
+ // Don't insert empty paths, they will make us abort the path
+ // search prematurely.
+ if (path.empty())
+ continue;
size_t path_size = path.size();
path_array.append(path);
path_array.push_back('\0');