~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to libclamav/upx.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
#include "others.h"
57
57
#include "upx.h"
58
58
#include "str.h"
 
59
#include "lzma_iface.h"
59
60
 
60
61
#define PEALIGN(o,a) (((a))?(((o)/(a))*(a)):(o))
61
62
#define PESALIGN(o,a) (((a))?(((o)/(a)+((o)%(a)!=0))*(a)):(o))
117
118
 
118
119
static int pefromupx (char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t ep, uint32_t upx0, uint32_t upx1, uint32_t *magic, uint32_t dend)
119
120
{
120
 
  char *imports, *sections, *pehdr=NULL, *newbuf;
 
121
  char *imports, *sections=NULL, *pehdr=NULL, *newbuf;
121
122
  unsigned int sectcnt=0, upd=1;
122
123
  uint32_t realstuffsz=0, valign=0;
123
124
  uint32_t foffset=0xd0+0xf8;
133
134
  }
134
135
 
135
136
  if (!valign && ep - upx1 + 0x80 < ssize-8) {
136
 
    char *pt = &src[ep - upx1 + 0x80];
 
137
    const char *pt = &src[ep - upx1 + 0x80];
137
138
    cli_dbgmsg("UPX: bad magic - scanning for imports\n");
138
139
    
139
 
    while ((pt=(char *)cli_memstr(pt, ssize - (pt-src) - 8, "\x8d\xbe", 2))) {
 
140
    while ((pt=cli_memstr(pt, ssize - (pt-src) - 8, "\x8d\xbe", 2))) {
140
141
      if (pt[6] == '\x8b' && pt[7] == '\x07') { /* lea edi, [esi+imports] / mov eax, [edi] */
141
142
        valign=pt-src+2-ep+upx1;
142
143
        break;
520
521
 
521
522
  return pefromupx (src, ssize, dst, dsize, ep, upx0, upx1, magic, dcur);
522
523
}
 
524
 
 
525
int upx_inflatelzma(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) {
 
526
  CLI_LZMA *lz = NULL;
 
527
  struct stream_state s;
 
528
  uint32_t magic[]={0xb16,0xb1e,0};
 
529
 
 
530
  cli_LzmaInitUPX(&lz, *dsize);
 
531
  s.avail_in = ssize;
 
532
  s.avail_out = *dsize;
 
533
  s.next_in = src+2;
 
534
  s.next_out = dst;
 
535
 
 
536
  if(cli_LzmaDecode(&lz, &s)==LZMA_RESULT_DATA_ERROR) {
 
537
/*     __asm__ __volatile__("int3"); */
 
538
    cli_LzmaShutdown(&lz);
 
539
    return -1;
 
540
  }
 
541
  cli_LzmaShutdown(&lz);
 
542
 
 
543
  return pefromupx (src, ssize, dst, dsize, ep, upx0, upx1, magic, *dsize);
 
544
}