[Lldb-commits] [lldb] r215741 - Don't crash when specifying a core file that isn't readable.

Greg Clayton gclayton at apple.com
Fri Aug 15 11:00:45 PDT 2014


Author: gclayton
Date: Fri Aug 15 13:00:45 2014
New Revision: 215741

URL: http://llvm.org/viewvc/llvm-project?rev=215741&view=rev
Log:
Don't crash when specifying a core file that isn't readable.

Fixes include:
1 - added new FileSpec method: bool FileSpec::Readable()
2 - detect when an executable is not readable and give an appropriate error for:
    (lldb) file /tmp/unreadablefile
3 - detect when a core file is not readable and give an appropriate error
4 - detect when a specified core file doesn't exist and give an appropriate error
    
<rdar://problem/17727734>


Modified:
    lldb/trunk/include/lldb/Host/FileSpec.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Host/common/FileSpec.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp

Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=215741&r1=215740&r2=215741&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Fri Aug 15 13:00:45 2014
@@ -270,6 +270,15 @@ public:
     bool
     Exists () const;
 
+    //------------------------------------------------------------------
+    /// Check if a file is readable by the current user
+    ///
+    /// @return
+    ///     \b true if the file exists on disk and is readable, \b false
+    ///     otherwise.
+    //------------------------------------------------------------------
+    bool
+    Readable () const;
      
     //------------------------------------------------------------------
     /// Expanded existence test.

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=215741&r1=215740&r2=215741&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri Aug 15 13:00:45 2014
@@ -230,12 +230,38 @@ protected:
         FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
         FileSpec remote_file (m_remote_file.GetOptionValue().GetCurrentValue());
 
+        if (core_file)
+        {
+            if (!core_file.Exists())
+            {
+                result.AppendErrorWithFormat("core file '%s' doesn't exist", core_file.GetPath().c_str());
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+                
+            }
+            if (!core_file.Readable())
+            {
+                result.AppendErrorWithFormat("core file '%s' is not readable", core_file.GetPath().c_str());
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
+        }
+
         if (argc == 1 || core_file || remote_file)
         {
             FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue());
             if (symfile)
             {
-                if (!symfile.Exists())
+                if (symfile.Exists())
+                {
+                    if (!symfile.Readable())
+                    {
+                        result.AppendErrorWithFormat("symbol file '%s' is not readable", core_file.GetPath().c_str());
+                        result.SetStatus (eReturnStatusFailed);
+                        return false;
+                    }
+                }
+                else
                 {
                     char symfile_path[PATH_MAX];
                     symfile.GetPath(symfile_path, sizeof(symfile_path));

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=215741&r1=215740&r2=215741&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Fri Aug 15 13:00:45 2014
@@ -483,6 +483,15 @@ FileSpec::Exists () const
 }
 
 bool
+FileSpec::Readable () const
+{
+    const uint32_t permissions = GetPermissions();
+    if (permissions & eFilePermissionsEveryoneR)
+        return true;
+    return false;
+}
+
+bool
 FileSpec::ResolveExecutableLocation ()
 {
     if (!m_directory)

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=215741&r1=215740&r2=215741&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Fri Aug 15 13:00:45 2014
@@ -139,7 +139,11 @@ PlatformDarwin::ResolveExecutable (const
     {
         // If we have "ls" as the exe_file, resolve the executable loation based on
         // the current path variables
-        if (!resolved_exe_file.Exists())
+        if (resolved_exe_file.Exists())
+        {
+            
+        }
+        else
         {
             exe_file.GetPath (exe_path, sizeof(exe_path));
             resolved_exe_file.SetFile(exe_path, true);
@@ -155,8 +159,11 @@ PlatformDarwin::ResolveExecutable (const
             error.Clear();
         else
         {
-            exe_file.GetPath (exe_path, sizeof(exe_path));
-            error.SetErrorStringWithFormat ("unable to find executable for '%s'", exe_path);
+            const uint32_t permissions = resolved_exe_file.GetPermissions();
+            if (permissions && (permissions & eFilePermissionsEveryoneR) == 0)
+                error.SetErrorStringWithFormat ("executable '%s' is not readable", resolved_exe_file.GetPath().c_str());
+            else
+                error.SetErrorStringWithFormat ("unable to find executable for '%s'", resolved_exe_file.GetPath().c_str());
         }
     }
     else
@@ -231,10 +238,17 @@ PlatformDarwin::ResolveExecutable (const
             
             if (error.Fail() || !exe_module_sp)
             {
-                error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
-                                                exe_file.GetPath().c_str(),
-                                                GetPluginName().GetCString(),
-                                                arch_names.GetString().c_str());
+                if (exe_file.Readable())
+                {
+                    error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
+                                                    exe_file.GetPath().c_str(),
+                                                    GetPluginName().GetCString(),
+                                                    arch_names.GetString().c_str());
+                }
+                else
+                {
+                    error.SetErrorStringWithFormat("'%s' is not readable", exe_file.GetPath().c_str());
+                }
             }
         }
     }

Modified: lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp?rev=215741&r1=215740&r2=215741&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp (original)
+++ lldb/trunk/source/Plugins/Process/mach-core/ProcessMachCore.cpp Fri Aug 15 13:00:45 2014
@@ -69,7 +69,7 @@ ProcessMachCore::CreateInstance (Target
     {
         const size_t header_size = sizeof(llvm::MachO::mach_header);
         lldb::DataBufferSP data_sp (crash_file->ReadFileContents(0, header_size));
-        if (data_sp->GetByteSize() == header_size)
+        if (data_sp && data_sp->GetByteSize() == header_size)
         {
             DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
             





More information about the lldb-commits mailing list