summaryrefslogtreecommitdiff
path: root/src/w32proc.c
diff options
context:
space:
mode:
authorSaulius Menkevičius <saulius.menkevicius@gmail.com>2017-07-09 21:16:17 +0300
committerEli Zaretskii <eliz@gnu.org>2017-07-09 21:16:17 +0300
commit51b29de1593c88ad801597ed840814616d16ef37 (patch)
tree23fde448ab3c0f64bf70e4c75e86366b8c292742 /src/w32proc.c
parent0cff089ec80f7b4cc6359718c791942f0f4079bf (diff)
downloademacs-51b29de1593c88ad801597ed840814616d16ef37.tar.gz
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
Diffstat (limited to 'src/w32proc.c')
-rw-r--r--src/w32proc.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index 0aa248a6f7b..76af55f9985 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;
+ }
}
- }
+ }
}
}
}