Commit 057dcdd6899b5a9c5abf6c47607cb95816e053a2

Silvio Traversaro 2023-07-04T08:57:43

Merge pull request #111 from pali/master Add missing check that section index in get_image_section() is valid

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/dlfcn.c b/src/dlfcn.c
index c4563d2..cb9f9bb 100644
--- a/src/dlfcn.c
+++ b/src/dlfcn.c
@@ -640,7 +640,7 @@ static BOOL get_image_section( HMODULE module, int index, void **ptr, DWORD *siz
     if( optionalHeader->Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC )
         return FALSE;
 
-    if( index < 0 || index >= IMAGE_NUMBEROF_DIRECTORY_ENTRIES )
+    if( index < 0 || index >= IMAGE_NUMBEROF_DIRECTORY_ENTRIES || index >= optionalHeader->NumberOfRvaAndSizes )
         return FALSE;
 
     if( optionalHeader->DataDirectory[index].Size == 0 || optionalHeader->DataDirectory[index].VirtualAddress == 0 )