emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 51b29de: Avoid crashes on MS-Windows starting 64-bi


From: Eli Zaretskii
Subject: [Emacs-diffs] master 51b29de: Avoid crashes on MS-Windows starting 64-bit .NET executables
Date: Sun, 9 Jul 2017 14:18:25 -0400 (EDT)

branch: master
commit 51b29de1593c88ad801597ed840814616d16ef37
Author: Saulius Menkevičius <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Avoid crashes on MS-Windows starting 64-bit .NET executables
    
    * src/w32proc.c (w32_executable_type): Don't assume that the
    import directory in a DLL will always be non-NULL.  (Bug#27527)
    
    Copyright-paperwork-exempt: yes
---
 src/w32proc.c | 63 ++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 34 insertions(+), 29 deletions(-)

diff --git a/src/w32proc.c b/src/w32proc.c
index 0aa248a..76af55f 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1622,38 +1622,43 @@ w32_executable_type (char * filename,
               /* Look for Cygwin DLL in the DLL import list. */
               IMAGE_DATA_DIRECTORY import_dir =
                 data_dir[IMAGE_DIRECTORY_ENTRY_IMPORT];
-              IMAGE_IMPORT_DESCRIPTOR * imports =
-               RVA_TO_PTR (import_dir.VirtualAddress,
-                           rva_to_section (import_dir.VirtualAddress,
-                                           nt_header),
-                           executable);
 
-              for ( ; imports->Name; imports++)
-                {
-                 IMAGE_SECTION_HEADER * section =
-                   rva_to_section (imports->Name, nt_header);
-                  char * dllname = RVA_TO_PTR (imports->Name, section,
-                                               executable);
-
-                  /* The exact name of the Cygwin DLL has changed with
-                     various releases, but hopefully this will be
-                     reasonably future-proof.  */
-                  if (strncmp (dllname, "cygwin", 6) == 0)
-                    {
-                      *is_cygnus_app = TRUE;
-                      break;
-                    }
-                 else if (strncmp (dllname, "msys-", 5) == 0)
+             /* Import directory can be missing in .NET DLLs.  */
+             if (import_dir.VirtualAddress != 0)
+               {
+                 IMAGE_IMPORT_DESCRIPTOR * imports =
+                   RVA_TO_PTR (import_dir.VirtualAddress,
+                               rva_to_section (import_dir.VirtualAddress,
+                                               nt_header),
+                               executable);
+
+                 for ( ; imports->Name; imports++)
                    {
-                     /* This catches both MSYS 1.x and MSYS2
-                        executables (the DLL name is msys-1.0.dll and
-                        msys-2.0.dll, respectively).  There doesn't
-                        seem to be a reason to distinguish between
-                        the two, for now.  */
-                     *is_msys_app = TRUE;
-                     break;
+                     IMAGE_SECTION_HEADER * section =
+                       rva_to_section (imports->Name, nt_header);
+                     char * dllname = RVA_TO_PTR (imports->Name, section,
+                                                  executable);
+
+                     /* The exact name of the Cygwin DLL has changed with
+                        various releases, but hopefully this will be
+                        reasonably future-proof.  */
+                     if (strncmp (dllname, "cygwin", 6) == 0)
+                       {
+                         *is_cygnus_app = TRUE;
+                         break;
+                       }
+                     else if (strncmp (dllname, "msys-", 5) == 0)
+                       {
+                         /* This catches both MSYS 1.x and MSYS2
+                            executables (the DLL name is msys-1.0.dll and
+                            msys-2.0.dll, respectively).  There doesn't
+                            seem to be a reason to distinguish between
+                            the two, for now.  */
+                         *is_msys_app = TRUE;
+                         break;
+                       }
                    }
-                }
+               }
             }
        }
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]