changeset 21366:516351d9a796

Some extra checks and safety space for add_stub function.
author reimar
date Wed, 29 Nov 2006 12:44:05 +0000
parents fef7a6713be2
children 731278c42d6c
files loader/win32.c
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/loader/win32.c	Wed Nov 29 12:20:05 2006 +0000
+++ b/loader/win32.c	Wed Nov 29 12:44:05 2006 +0000
@@ -5278,16 +5278,22 @@
 
 //static void add_stub(int pos)
 
+#define MAX_STUB_SIZE 0x60
+#define MAX_NUM_STUBS 200
 static int pos=0;
-static char extcode[20000];// place for 200 unresolved exports
+static char extcode[MAX_NUM_STUBS * MAX_STUB_SIZE];
 
 static void* add_stub(void)
 {
     int i;
     // generated code in runtime!
-    char* answ = (char*)extcode+pos*0x30;
-    memcpy(answ, ext_stubs, 0x2f); // 0x2c is current size
-    for (i = 0; i < 0x30 - 3; i++) {
+    char* answ = extcode + pos * MAX_STUB_SIZE;
+    if (pos >= MAX_NUM_STUBS) {
+      printf("too many stubs, expect crash\n");
+      return NULL;
+    }
+    memcpy(answ, ext_stubs, MAX_STUB_SIZE);
+    for (i = 0; i < MAX_STUB_SIZE - 3; i++) {
       if (*(int*)(answ + i) == 0xdeadabcd)
         break;
     }