[Lldb-commits] [lldb] r337515 - Defend LoadImageUsingPaths against a path list

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 19 18:20:18 PDT 2018


Author: jingham
Date: Thu Jul 19 18:20:18 2018
New Revision: 337515

URL: http://llvm.org/viewvc/llvm-project?rev=337515&view=rev
Log:
Defend LoadImageUsingPaths against a path list
with empty paths on it.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
    lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py?rev=337515&r1=337514&r2=337515&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py Thu Jul 19 18:20:18 2018
@@ -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:

Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=337515&r1=337514&r2=337515&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Thu Jul 19 18:20:18 2018
@@ -1155,6 +1155,10 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb
     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');




More information about the lldb-commits mailing list