Browse code

Better handling for emu error

git-svn: trunk@2157

aCaB authored on 2006/08/01 01:34:20
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Jul 31 18:24:36 CEST 2006 (acab)
2
+------------------------------------
3
+  * libclamav: better error handling in pespin
4
+
1 5
 Mon Jul 31 14:23:30 CEST 2006 (acab)
2 6
 ------------------------------------
3 7
   * libclamav: share aPLib code
... ...
@@ -17,9 +17,9 @@
17 17
  *  MA 02110-1301, USA.
18 18
  */
19 19
 
20
-#ifndef __SPIN_H
21
-#define __SPIN_H
20
+#ifndef __PACKLIBS_H
21
+#define __PACKLIBS_H
22 22
 
23
-cli_unfsg(char *, char *, int, int, char **, char **);
23
+int cli_unfsg(char *, char *, int, int, char **, char **);
24 24
 
25 25
 #endif
... ...
@@ -67,8 +67,9 @@
67 67
 
68 68
 #define EC32(x) le32_to_host(x) /* Convert little endian to host */
69 69
 
70
-static char exec86(uint8_t aelle, uint8_t cielle, char *curremu) {
70
+static char exec86(uint8_t aelle, uint8_t cielle, char *curremu, int *retval) {
71 71
   int len = 0;
72
+  *retval=0;
72 73
   while (len <0x24) {
73 74
     uint8_t opcode = curremu[len], support;
74 75
     len++;
... ...
@@ -122,11 +123,15 @@ static char exec86(uint8_t aelle, uint8_t cielle, char *curremu) {
122 122
         break;
123 123
 
124 124
       default:
125
-        cli_dbgmsg("Bogus opcode %x\n", opcode);
125
+        cli_dbgmsg("spin: bogus opcode %x\n", opcode);
126
+	*retval=1;
127
+	return aelle;
126 128
     }
127 129
   }
128
-  if ( len!=0x24 || curremu[len]!='\xaa' )
129
-    cli_dbgmsg("spin: bad emucode\n"); /* FIXME: I should really give up here */
130
+  if ( len!=0x24 || curremu[len]!='\xaa' ) {
131
+    cli_dbgmsg("spin: bad emucode\n");
132
+    *retval=1;
133
+  }
130 134
   return aelle;
131 135
 }
132 136
 
... ...
@@ -329,7 +334,12 @@ int unspin(char *src, int ssize, struct pe_image_section_hdr *sections, int sect
329 329
     return 1;
330 330
   }
331 331
   while (len) {
332
-    *emu=exec86(*emu, len-- & 0xff, curr); /* unlame POLY1 */
332
+    int xcfailure=0;
333
+    *emu=exec86(*emu, len-- & 0xff, curr, &xcfailure); /* unlame POLY1 */
334
+    if (xcfailure) {
335
+      cli_dbgmsg("spin: cannot exec poly1\n");
336
+      return 1;
337
+    }
333 338
     emu++;
334 339
   }
335 340
 
... ...
@@ -350,7 +360,12 @@ int unspin(char *src, int ssize, struct pe_image_section_hdr *sections, int sect
350 350
       }
351 351
 
352 352
       while (notthesamelen) {
353
-        *emu=exec86(*emu, notthesamelen-- & 0xff, curr);
353
+	int xcfailure=0;
354
+        *emu=exec86(*emu, notthesamelen-- & 0xff, curr, &xcfailure);
355
+	if (xcfailure) {
356
+	  cli_dbgmsg("spin: cannot exec section\n");
357
+	  return 1;
358
+	}
354 359
         emu++;
355 360
       }
356 361
     }