sect align fix in mew

git-svn: trunk@2643
remotes/push_mirror/metadata
aCaB 19 years ago
parent 0883760581
commit 52ed82a4aa
  1. 4
      clamav-devel/ChangeLog
  2. 33
      clamav-devel/libclamav/mew.c

@ -1,3 +1,7 @@
Fri Jan 26 20:49:07 CET 2007 (acab)
-----------------------------------
* libclamav/mew.c: fix align logic, added some sanity checks
Fri Jan 26 20:46:30 CET 2007 (tk) Fri Jan 26 20:46:30 CET 2007 (tk)
--------------------------------- ---------------------------------
* libclamav/clamav.h: use 'unsigned char' for cli_ac_patt.altc * libclamav/clamav.h: use 'unsigned char' for cli_ac_patt.altc

@ -47,6 +47,8 @@
#define EC32(x) le32_to_host(x) /* Convert little endian to host */ #define EC32(x) le32_to_host(x) /* Convert little endian to host */
#define CE32(x) be32_to_host(x) /* Convert big endian to host */ #define CE32(x) be32_to_host(x) /* Convert big endian to host */
#define PEALIGN(o,a) (((a))?(((o)/(a))*(a)):(o))
#define PESALIGN(o,a) (((a))?(((o)/(a)+((o)%(a)!=0))*(a)):(o))
/* modifies all parameters */ /* modifies all parameters */
/* northfox does this shitty way, /* northfox does this shitty way,
@ -806,18 +808,27 @@ int unmew11(int sectnum, char *src, int off, int ssize, int dsize, uint32_t base
if (!uselzma) if (!uselzma)
{ {
uint32_t val = f2 - src; uint32_t val = PESALIGN(f2 - src, 0x1000);
/* round-up to 4k boundary, I'm not sure of this XXX */ void *newsect;
val >>= 12;
val <<= 12; if (i && val < section[i].raw) {
val += 0x1000; cli_dbgmsg("MEW: WTF - please report\n");
free(section);
/* eeevil XXX */ return -1;
section = cli_realloc(section, (i+2)*sizeof(struct cli_exe_section)); }
section[0].raw = 0; section[0].rva = vadd;
if (!(newsect=cli_realloc(section, (i+2)*sizeof(struct cli_exe_section)))) {
cli_dbgmsg("MEW: Out of memory\n");
free(section);
return -1;
}
section = (struct cli_exe_section *)newsect;
section[0].raw = 0;
section[0].rva = vadd;
section[i+1].raw = val; section[i+1].raw = val;
section[i+1].rva = val + vadd; section[i+1].rva = val + vadd;
section[i].rsz = section[i].vsz = i?val - section[i].raw:val; section[i].rsz = section[i].vsz = ((i)?(val - section[i].raw):val);
} }
i++; i++;
@ -849,7 +860,7 @@ int unmew11(int sectnum, char *src, int off, int ssize, int dsize, uint32_t base
free(section); free(section);
return -1; return -1;
} }
loc_ds >>= 12; loc_ds <<= 12; loc_ds += 0x1000; loc_ds=PESALIGN(loc_ds, 0x1000);
section = cli_calloc(1, sizeof(struct cli_exe_section)); section = cli_calloc(1, sizeof(struct cli_exe_section));
section[0].raw = 0; section[0].rva = vadd; section[0].raw = 0; section[0].rva = vadd;

Loading…
Cancel
Save