git-svn: trunk@2643
aCaB authored on 2007/01/27 04:52:31... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Fri Jan 26 20:49:07 CET 2007 (acab) |
|
2 |
+----------------------------------- |
|
3 |
+ * libclamav/mew.c: fix align logic, added some sanity checks |
|
4 |
+ |
|
1 | 5 |
Fri Jan 26 20:46:30 CET 2007 (tk) |
2 | 6 |
--------------------------------- |
3 | 7 |
* libclamav/clamav.h: use 'unsigned char' for cli_ac_patt.altc |
... | ... |
@@ -47,6 +47,8 @@ |
47 | 47 |
|
48 | 48 |
#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
49 | 49 |
#define CE32(x) be32_to_host(x) /* Convert big endian to host */ |
50 |
+#define PEALIGN(o,a) (((a))?(((o)/(a))*(a)):(o)) |
|
51 |
+#define PESALIGN(o,a) (((a))?(((o)/(a)+((o)%(a)!=0))*(a)):(o)) |
|
50 | 52 |
|
51 | 53 |
/* modifies all parameters */ |
52 | 54 |
/* northfox does this shitty way, |
... | ... |
@@ -806,18 +808,27 @@ int unmew11(int sectnum, char *src, int off, int ssize, int dsize, uint32_t base |
806 | 806 |
|
807 | 807 |
if (!uselzma) |
808 | 808 |
{ |
809 |
- uint32_t val = f2 - src; |
|
810 |
- /* round-up to 4k boundary, I'm not sure of this XXX */ |
|
811 |
- val >>= 12; |
|
812 |
- val <<= 12; |
|
813 |
- val += 0x1000; |
|
814 |
- |
|
815 |
- /* eeevil XXX */ |
|
816 |
- section = cli_realloc(section, (i+2)*sizeof(struct cli_exe_section)); |
|
817 |
- section[0].raw = 0; section[0].rva = vadd; |
|
809 |
+ uint32_t val = PESALIGN(f2 - src, 0x1000); |
|
810 |
+ void *newsect; |
|
811 |
+ |
|
812 |
+ if (i && val < section[i].raw) { |
|
813 |
+ cli_dbgmsg("MEW: WTF - please report\n"); |
|
814 |
+ free(section); |
|
815 |
+ return -1; |
|
816 |
+ } |
|
817 |
+ |
|
818 |
+ if (!(newsect=cli_realloc(section, (i+2)*sizeof(struct cli_exe_section)))) { |
|
819 |
+ cli_dbgmsg("MEW: Out of memory\n"); |
|
820 |
+ free(section); |
|
821 |
+ return -1; |
|
822 |
+ } |
|
823 |
+ |
|
824 |
+ section = (struct cli_exe_section *)newsect; |
|
825 |
+ section[0].raw = 0; |
|
826 |
+ section[0].rva = vadd; |
|
818 | 827 |
section[i+1].raw = val; |
819 | 828 |
section[i+1].rva = val + vadd; |
820 |
- section[i].rsz = section[i].vsz = i?val - section[i].raw:val; |
|
829 |
+ section[i].rsz = section[i].vsz = ((i)?(val - section[i].raw):val); |
|
821 | 830 |
} |
822 | 831 |
i++; |
823 | 832 |
|
... | ... |
@@ -849,7 +860,7 @@ int unmew11(int sectnum, char *src, int off, int ssize, int dsize, uint32_t base |
849 | 849 |
free(section); |
850 | 850 |
return -1; |
851 | 851 |
} |
852 |
- loc_ds >>= 12; loc_ds <<= 12; loc_ds += 0x1000; |
|
852 |
+ loc_ds=PESALIGN(loc_ds, 0x1000); |
|
853 | 853 |
|
854 | 854 |
section = cli_calloc(1, sizeof(struct cli_exe_section)); |
855 | 855 |
section[0].raw = 0; section[0].rva = vadd; |