~ubuntu-branches/ubuntu/trusty/clamav/trusty-proposed

« back to all changes in this revision

Viewing changes to libclamav/ishield.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-01 11:06:17 UTC
  • mfrom: (0.35.37 sid)
  • Revision ID: package-import@ubuntu.com-20140201110617-33h2xxk09dep0ui4
Tags: 0.98.1+dfsg-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Add autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
193
193
 
194
194
/* Extracts the content of MSI based IS */
195
195
int cli_scanishield_msi(cli_ctx *ctx, off_t off) {
196
 
    uint8_t *buf;
 
196
    const uint8_t *buf;
197
197
    unsigned int fcount, scanned = 0;
198
198
    int ret;
199
199
    fmap_t *map = *ctx->fmap;
298
298
        if (ret == CL_SUCCESS) {
299
299
            cli_dbgmsg("ishield-msi: extracted to %s\n", tempfile);
300
300
 
301
 
            lseek(ofd, 0, SEEK_SET);
 
301
            if (lseek(ofd, 0, SEEK_SET) == -1) {
 
302
            cli_dbgmsg("ishield-msi: call to lseek() failed\n");
 
303
            ret = CL_ESEEK;
 
304
        }
302
305
            ret = cli_magic_scandesc(ofd, ctx);
303
306
        }
304
307
        close(ofd);
337
340
 
338
341
/* Extract the content of older (non-MSI) IS */
339
342
int cli_scanishield(cli_ctx *ctx, off_t off, size_t sz) {
340
 
    char *fname, *path, *version, *strsz, *eostr, *data;
 
343
    const char *fname, *path, *version, *strsz, *data;
 
344
    char *eostr;
341
345
    int ret = CL_CLEAN;
342
346
    long fsize;
343
347
    off_t coff = off;
344
348
    struct IS_CABSTUFF c = { NULL, -1, 0, 0 };
345
349
    fmap_t *map = *ctx->fmap;
 
350
    unsigned fc = 0;
346
351
 
347
352
    while(ret == CL_CLEAN) {
348
353
        fname = fmap_need_offstr(map, coff, 2048);
371
376
        ) break;
372
377
 
373
378
        cli_dbgmsg("ishield: @%lx found file %s (%s) - version %s - size %lu\n", (unsigned long int) coff, fname, path, version, (unsigned long int) fsize);
 
379
        if(cli_matchmeta(ctx, fname, fsize, fsize, 0, fc++, 0, NULL) == CL_VIRUS) {
 
380
            ret = CL_VIRUS;
 
381
            break;
 
382
        }
374
383
        sz -= (data - fname) + fsize;
375
384
 
376
385
        if(!strncasecmp(fname, "data", 4)) {
431
440
 
432
441
/* Utility func to scan a fd @ a given offset and size */
433
442
static int is_dump_and_scan(cli_ctx *ctx, off_t off, size_t fsize) {
434
 
    char *fname, *buf;
 
443
    char *fname;
 
444
    const char *buf;
435
445
    int ofd, ret = CL_CLEAN;
436
446
    fmap_t *map = *ctx->fmap;
437
447
 
463
473
    }
464
474
    if(!fsize) {
465
475
        cli_dbgmsg("ishield: extracted to %s\n", fname);
466
 
        lseek(ofd, 0, SEEK_SET);
 
476
        if (lseek(ofd, 0, SEEK_SET) == -1) {
 
477
        cli_dbgmsg("ishield: call to lseek() failed\n");
 
478
        ret = CL_ESEEK;
 
479
    }
467
480
        ret = cli_magic_scandesc(ofd, ctx);
468
481
    }
469
482
    close(ofd);
481
494
    char hash[33], *hdr;
482
495
    fmap_t *map = *ctx->fmap;
483
496
 
484
 
    struct IS_HDR *h1;
 
497
    const struct IS_HDR *h1;
485
498
    struct IS_OBJECTS *objs;
486
499
    /* struct IS_INSTTYPEHDR *typehdr; -- UNUSED */
487
500
 
670
683
#define IS_CABBUFSZ 65536
671
684
 
672
685
static int is_extract_cab(cli_ctx *ctx, uint64_t off, uint64_t size, uint64_t csize) {
673
 
    uint8_t *inbuf, *outbuf;
 
686
    const uint8_t *inbuf;
 
687
    uint8_t *outbuf;
674
688
    char *tempfile;
675
689
    int ofd, ret = CL_CLEAN;
676
690
    z_stream z;
678
692
    int success = 0;
679
693
    fmap_t *map = *ctx->fmap;
680
694
 
681
 
    if(!(outbuf = cli_malloc(IS_CABBUFSZ)))
682
 
        return CL_EMEM;
 
695
    if(!(outbuf = cli_malloc(IS_CABBUFSZ))) {
 
696
        cli_errmsg("is_extract_cab: Unable to allocate memory for outbuf\n");
 
697
        return CL_EMEM;
 
698
    }
683
699
 
684
700
    if(!(tempfile = cli_gentemp(ctx->engine->tmpdir))) {
685
701
        free(outbuf);
758
774
            cli_dbgmsg("is_extract_cab: extracted %llu bytes to %s, expected %llu, scanning anyway.\n", (long long)outsz, tempfile, (long long)size);
759
775
        else
760
776
            cli_dbgmsg("is_extract_cab: extracted to %s\n", tempfile);
761
 
        lseek(ofd, 0, SEEK_SET);
 
777
        if (lseek(ofd, 0, SEEK_SET) == -1)
 
778
        cli_dbgmsg("is_extract_cab: call to lseek() failed\n");
762
779
        ret = cli_magic_scandesc(ofd, ctx);
763
780
    }
764
781