~yolanda.robla/ubuntu/saucy/clamav/dep-8-tests

« back to all changes in this revision

Viewing changes to libclamav/regex_list.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-11-02 23:27:19 UTC
  • mfrom: (0.35.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091102232719-61ay35095dhbuxfm
Tags: 0.95.3+dfsg-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Build-dep on libltdl3-dev instead of libltdl-dev for updating earlier
    releases more easily
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
#include "jsparse/textbuf.h"
55
55
#include "regex_suffix.h"
56
56
#include "default.h"
 
57
#include "hashtab.h"
57
58
 
58
59
#include "mpool.h"
59
60
 
361
362
        matcher->list_inited=1;
362
363
        matcher->list_built=0;
363
364
        matcher->list_loaded=0;
364
 
        hashtab_init(&matcher->suffix_hash, 512);
 
365
        cli_hashtab_init(&matcher->suffix_hash, 512);
365
366
#ifdef USE_MPOOL
366
367
        matcher->mempool = mp;
367
368
        matcher->suffixes.mempool = mp;
446
447
            bm = &matcher->sha256_hashes;
447
448
        }
448
449
 
 
450
        if (!matcher->sha256_pfx_set.keys) {
 
451
            if((rc = cli_hashset_init(&matcher->sha256_pfx_set, 1048576, 90))) {
 
452
                return rc;
 
453
            }
 
454
        }
 
455
 
449
456
        if (fl != 'W' && pat->length == 32 &&
450
 
            cli_bm_scanbuff(pat->pattern, 32, &vname, &matcher->sha256_hashes,0,0,-1) == CL_VIRUS) {
 
457
            cli_hashset_contains(&matcher->sha256_pfx_set, cli_readint32(pat->pattern)) &&
 
458
            cli_bm_scanbuff(pat->pattern, 32, &vname, NULL, &matcher->sha256_hashes,0,0,-1) == CL_VIRUS) {
451
459
            if (*vname == 'W') {
452
460
                /* hash is whitelisted in local.gdb */
453
461
                cli_dbgmsg("Skipping hash %s\n", pattern);
462
470
                return CL_EMEM;
463
471
        }
464
472
        *pat->virname = fl;
465
 
 
 
473
        cli_hashset_addkey(&matcher->sha256_pfx_set, cli_readint32(pat->pattern));
466
474
        if((rc = cli_bm_addpatt(bm, pat))) {
467
475
                cli_errmsg("add_hash: failed to add BM pattern\n");
468
476
                free(pat->pattern);
599
607
                return -1;/*TODO: better error code */
600
608
        }
601
609
        cli_dbgmsg("Building regex list\n");
602
 
        hashtab_free(&matcher->suffix_hash);
 
610
        cli_hashtab_free(&matcher->suffix_hash);
603
611
        if(( rc = cli_ac_buildtrie(&matcher->suffixes) ))
604
612
                return rc;
605
613
        matcher->list_built=1;
 
614
        cli_hashset_destroy(&matcher->sha256_pfx_set);
606
615
 
607
616
        return CL_SUCCESS;
608
617
}
636
645
                        }
637
646
                        mpool_free(matcher->mempool, matcher->all_pregs);
638
647
                }
639
 
                hashtab_free(&matcher->suffix_hash);
 
648
                cli_hashtab_free(&matcher->suffix_hash);
640
649
                cli_bm_free(&matcher->sha256_hashes);
641
650
                cli_bm_free(&matcher->hostkey_prefix);
642
651
        }
710
719
{
711
720
        struct regex_matcher *matcher = cbdata;
712
721
        struct regex_list *regex = cli_malloc(sizeof(*regex));
713
 
        const struct element *el;
 
722
        const struct cli_element *el;
714
723
 
715
724
        assert(matcher);
716
725
        if(!regex)
718
727
        regex->pattern = iregex->pattern ? cli_strdup(iregex->pattern) : NULL;
719
728
        regex->preg = iregex->preg;
720
729
        regex->nxt = NULL;
721
 
        el = hashtab_find(&matcher->suffix_hash, suffix, suffix_len);
 
730
        el = cli_hashtab_find(&matcher->suffix_hash, suffix, suffix_len);
722
731
        /* TODO: what if suffixes are prefixes of eachother and only one will
723
732
         * match? */
724
733
        if(el) {
725
734
                /* existing suffix */
726
735
                assert((size_t)el->data < matcher->suffix_cnt);
727
736
                list_add_tail(&matcher->suffix_regexes[el->data], regex);
728
 
                cli_dbgmsg(MODULE "added new regex to existing suffix %s: %s\n", suffix, regex->pattern);
729
737
        } else {
730
738
                /* new suffix */
731
739
                size_t n = matcher->suffix_cnt++;
732
 
                el = hashtab_insert(&matcher->suffix_hash, suffix, suffix_len, n);
 
740
                el = cli_hashtab_insert(&matcher->suffix_hash, suffix, suffix_len, n);
733
741
                matcher->suffix_regexes = cli_realloc(matcher->suffix_regexes, (n+1)*sizeof(*matcher->suffix_regexes));
734
742
                if(!matcher->suffix_regexes)
735
743
                        return CL_EMEM;
738
746
                if (suffix[0] == '/' && suffix[1] == '\0')
739
747
                    matcher->root_regex_idx = n;
740
748
                add_newsuffix(matcher, regex, suffix, suffix_len);
741
 
                cli_dbgmsg(MODULE "added new suffix %s, for regex: %s\n", suffix, regex->pattern);
742
749
        }
743
750
        return 0;
744
751
}