~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

Viewing changes to libclamav/ole2_extract.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <stdlib.h>
36
36
#include "clamav.h"
37
37
 
 
38
#include <openssl/ssl.h>
 
39
#include <openssl/err.h>
 
40
#include "libclamav/crypto.h"
 
41
 
38
42
#include "cltypes.h"
39
43
#include "others.h"
40
44
#include "ole2_extract.h"
511
515
    int32_t         idx, current_block, i, curindex;
512
516
    char           *dirname;
513
517
    ole2_list_t     node_list;
514
 
    int             ret;
 
518
    int             ret, func_ret;
515
519
 
516
520
    ole2_listmsg("ole2_walk_property_tree() called\n");
 
521
    func_ret = CL_SUCCESS;
517
522
    ole2_list_init(&node_list);
518
523
 
519
524
    ole2_listmsg("rec_level: %d\n", rec_level);
600
605
                continue;
601
606
            }
602
607
            hdr->sbat_root_start = prop_block[idx].start_block;
603
 
            if ((prop_block[idx].child != -1) &&
604
 
                    (ret = ole2_walk_property_tree(hdr, dir, prop_block[idx].child, handler, rec_level + 1, file_count, ctx, scansize)) != CL_SUCCESS) {
605
 
                ole2_list_delete(&node_list);
606
 
                return ret;
 
608
            if (prop_block[idx].child != -1) {
 
609
                ret = ole2_walk_property_tree(hdr, dir, prop_block[idx].child, handler, rec_level + 1, file_count, ctx, scansize);
 
610
                if (ret != CL_SUCCESS) {
 
611
                    if ((ctx->options & CL_SCAN_ALLMATCHES) && (ret == CL_VIRUS)) {
 
612
                        func_ret = ret;
 
613
                    }
 
614
                    else {
 
615
                        ole2_list_delete(&node_list);
 
616
                        return ret;
 
617
                    }
 
618
                }
607
619
            }
608
620
            if (prop_block[idx].prev != -1) {
609
621
                if ((ret=ole2_list_push(&node_list, prop_block[idx].prev)) != CL_SUCCESS) {
623
635
            if (ctx && ctx->engine->maxfiles && ctx->scannedfiles + *file_count > ctx->engine->maxfiles) {
624
636
                cli_dbgmsg("OLE2: files limit reached (max: %u)\n", ctx->engine->maxfiles);
625
637
                ole2_list_delete(&node_list);
626
 
                return CL_BREAK;
 
638
                return CL_EMAXFILES;
627
639
            }
628
640
            if (!ctx || !(ctx->engine->maxfilesize) || prop_block[idx].size <= ctx->engine->maxfilesize || prop_block[idx].size <= *scansize) {
629
641
                (*file_count)++;
630
642
                *scansize -= prop_block[idx].size;
631
643
                ole2_listmsg("running file handler\n");
632
 
                if ((ret = handler(hdr, &prop_block[idx], dir, ctx)) != CL_SUCCESS) {
633
 
                    ole2_listmsg("file handler returned %d\n", ret);
634
 
                    ole2_list_delete(&node_list);
635
 
                    return ret;
 
644
                ret = handler(hdr, &prop_block[idx], dir, ctx);
 
645
                if (ret != CL_SUCCESS) {
 
646
                    if ((ctx->options & CL_SCAN_ALLMATCHES) && (ret == CL_VIRUS)) {
 
647
                        func_ret = ret;
 
648
                    }
 
649
                    else {
 
650
                        ole2_listmsg("file handler returned %d\n", ret);
 
651
                        ole2_list_delete(&node_list);
 
652
                        return ret;
 
653
                    }
636
654
                }
637
655
            } else {
638
656
                cli_dbgmsg("OLE2: filesize exceeded\n");
639
657
            }
640
 
            if ((prop_block[idx].child != -1) &&
641
 
                    (ret = ole2_walk_property_tree(hdr, dir, prop_block[idx].child, handler, rec_level, file_count, ctx, scansize)) != CL_SUCCESS) {
642
 
                ole2_list_delete(&node_list);
643
 
                return ret;
 
658
            if (prop_block[idx].child != -1) {
 
659
                ret = ole2_walk_property_tree(hdr, dir, prop_block[idx].child, handler, rec_level, file_count, ctx, scansize);
 
660
                if (ret != CL_SUCCESS) {
 
661
                    if ((ctx->options & CL_SCAN_ALLMATCHES) && (ret == CL_VIRUS)) {
 
662
                        func_ret = ret;
 
663
                    }
 
664
                    else {
 
665
                        ole2_list_delete(&node_list);
 
666
                        return ret;
 
667
                    }
 
668
                }
644
669
            }
645
670
            if (prop_block[idx].prev != -1) {
646
671
                if ((ret=ole2_list_push(&node_list, prop_block[idx].prev)) != CL_SUCCESS) {
674
699
                cli_dbgmsg("OLE2 dir entry: %s\n", dirname);
675
700
            } else
676
701
                dirname = NULL;
677
 
            if ((prop_block[idx].child != -1) &&
678
 
                    (ret = ole2_walk_property_tree(hdr, dirname, prop_block[idx].child, handler, rec_level + 1, file_count, ctx, scansize)) != CL_SUCCESS) {
679
 
                ole2_list_delete(&node_list);
680
 
                return ret;
 
702
            if (prop_block[idx].child != -1) {
 
703
                ret = ole2_walk_property_tree(hdr, dirname, prop_block[idx].child, handler, rec_level + 1, file_count, ctx, scansize);
 
704
                if (ret != CL_SUCCESS) {
 
705
                    if ((ctx->options & CL_SCAN_ALLMATCHES) && (ret == CL_VIRUS)) {
 
706
                        func_ret = ret;
 
707
                    }
 
708
                    else {
 
709
                        ole2_list_delete(&node_list);
 
710
                        return ret;
 
711
                    }
 
712
                }
681
713
            }
682
714
            if (prop_block[idx].prev != -1) {
683
715
                if ((ret=ole2_list_push(&node_list, prop_block[idx].prev)) != CL_SUCCESS) {
701
733
        ole2_listmsg("loop ended: %d %d\n", ole2_list_size(&node_list), ole2_list_is_empty(&node_list));
702
734
    }
703
735
    ole2_list_delete(&node_list);
704
 
    return CL_SUCCESS;
 
736
    return func_ret;
705
737
}
706
738
 
707
739
/* Write file Handler - write the contents of the entry to a file */
945
977
    }
946
978
 
947
979
    if (lseek(ofd, 0, SEEK_SET) == -1) {
 
980
        close(ofd);
 
981
        if (ctx && !(ctx->engine->keeptmp))
 
982
            cli_unlink(tempfile);
 
983
 
 
984
        free(tempfile);
 
985
        free(buff);
 
986
        cli_bitset_free(blk_bitset);
948
987
        return CL_ESEEK;
949
988
    }
950
989
    ret = cli_magic_scandesc(ofd, ctx);