~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/readdb.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mfrom: (0.7.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070220103344-yrxzd2x7lhee3r02
Tags: 0.90-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/clamav-base.init-stub, debian/clamav-daemon.init,
    debian/rules: init script stub for common setup functions.
  - debian/control: Maintainers updated for Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
#include "defaults.h"
51
51
#include "dconf.h"
52
52
#include "lockdb.h"
 
53
#include "readdb.h"
53
54
 
54
55
#ifdef CL_EXPERIMENTAL
 
56
#include "phishcheck.h"
55
57
#include "phish_whitelist.h"
56
58
#include "phish_domaincheck_db.h"
57
59
#include "regex_list.h"
905
907
            if(!(*engine)->md5_sect) {
906
908
                (*engine)->md5_sect = new;
907
909
            } else {
908
 
                if(new->size < (*engine)->md5_sect->size) {
 
910
                if(new->size <= (*engine)->md5_sect->size) {
909
911
                    new->next = (*engine)->md5_sect;
910
912
                    (*engine)->md5_sect = new;
911
913
                } else {
912
914
                    mpt = (*engine)->md5_sect;
913
915
                    while(mpt) {
914
916
                        last = mpt;
915
 
                        if((mpt->size < new->size) && (!mpt->next || new->size < mpt->next->size))
 
917
                        if(!mpt->next || new->size <= mpt->next->size)
916
918
                            break;
917
919
                        mpt = mpt->next;
918
920
                    }
1399
1401
 
1400
1402
    if((dd = opendir(dirname)) == NULL) {
1401
1403
        cli_errmsg("cl_statdbdir(): Can't open directory %s\n", dirname);
 
1404
        cl_statfree(dbstat);
1402
1405
        return CL_EOPEN;
1403
1406
    }
1404
1407
 
1436
1439
            cli_strbcasestr(dent->d_name, ".cvd"))) {
1437
1440
 
1438
1441
                dbstat->entries++;
1439
 
                dbstat->stattab = (struct stat *) realloc(dbstat->stattab, dbstat->entries * sizeof(struct stat));
 
1442
                dbstat->stattab = (struct stat *) cli_realloc(dbstat->stattab, dbstat->entries * sizeof(struct stat));
 
1443
                if(!dbstat->stattab) {
 
1444
                    /* FIXME: Minor error path memleak here. Change the
 
1445
                     * behaviour of cli_realloc() to free old block on error
 
1446
                     * (and review all calls to cli_realloc()).
 
1447
                     */
 
1448
                    cl_statfree(dbstat);
 
1449
                    closedir(dd);
 
1450
                    return CL_EMEM;
 
1451
                }
 
1452
 
1440
1453
#if defined(C_INTERIX) || defined(C_OS2)
1441
 
                dbstat->statdname = (char **) realloc(dbstat->statdname, dbstat->entries * sizeof(char *));
 
1454
                dbstat->statdname = (char **) cli_realloc(dbstat->statdname, dbstat->entries * sizeof(char *));
 
1455
                if(!dbstat->statdname) {
 
1456
                    cl_statfree(dbstat);
 
1457
                    closedir(dd);
 
1458
                    return CL_EMEM;
 
1459
                }
1442
1460
#endif
1443
1461
 
1444
1462
                fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 32, sizeof(char));
 
1463
                if(!fname) {
 
1464
                    cl_statfree(dbstat);
 
1465
                    closedir(dd);
 
1466
                    return CL_EMEM;
 
1467
                }
 
1468
 
1445
1469
                if(cli_strbcasestr(dent->d_name, ".inc")) {
1446
1470
                    if(strstr(dent->d_name, "main"))
1447
1471
                        sprintf(fname, "%s/main.inc/main.info", dirname);
1452
1476
                }
1453
1477
#if defined(C_INTERIX) || defined(C_OS2)
1454
1478
                dbstat->statdname[dbstat->entries - 1] = (char *) cli_calloc(strlen(dent->d_name) + 1, sizeof(char));
 
1479
                if(!dbstat->statdname[dbstat->entries - 1]) {
 
1480
                    cl_statfree(dbstat);
 
1481
                    closedir(dd);
 
1482
                    return CL_EMEM;
 
1483
                }
 
1484
 
1455
1485
                strcpy(dbstat->statdname[dbstat->entries - 1], dent->d_name);
1456
1486
#endif
1457
1487
                stat(fname, &dbstat->stattab[dbstat->entries - 1]);
1523
1553
            cli_strbcasestr(dent->d_name, ".cvd"))) {
1524
1554
 
1525
1555
                fname = cli_calloc(strlen(dbstat->dir) + strlen(dent->d_name) + 32, sizeof(char));
 
1556
                if(!fname) {
 
1557
                    closedir(dd);
 
1558
                    return CL_EMEM;
 
1559
                }
 
1560
 
1526
1561
                if(cli_strbcasestr(dent->d_name, ".inc")) {
1527
1562
                    if(strstr(dent->d_name, "main"))
1528
1563
                        sprintf(fname, "%s/main.inc/main.info", dbstat->dir);
1568
1603
#if defined(C_INTERIX) || defined(C_OS2)
1569
1604
            int i;
1570
1605
 
1571
 
        for(i = 0;i < dbstat->entries; i++) {
1572
 
            free(dbstat->statdname[i]);
1573
 
            dbstat->statdname[i] = NULL;
 
1606
        if(dbstat->statdname) {
 
1607
            for(i = 0; i < dbstat->entries; i++) {
 
1608
                if(dbstat->statdname[i])
 
1609
                    free(dbstat->statdname[i]);
 
1610
                dbstat->statdname[i] = NULL;
 
1611
            }
 
1612
            free(dbstat->statdname);
 
1613
            dbstat->statdname = NULL;
1574
1614
        }
1575
 
        free(dbstat->statdname);
1576
 
        dbstat->statdname = NULL;
1577
1615
#endif
1578
1616
 
1579
 
        free(dbstat->stattab);
1580
 
        dbstat->stattab = NULL;
 
1617
        if(dbstat->stattab) {
 
1618
            free(dbstat->stattab);
 
1619
            dbstat->stattab = NULL;
 
1620
        }
1581
1621
        dbstat->entries = 0;
 
1622
 
1582
1623
        if(dbstat->dir) {
1583
1624
            free(dbstat->dir);
1584
1625
            dbstat->dir = NULL;
1681
1722
    if(engine->dconf)
1682
1723
        free(engine->dconf);
1683
1724
 
 
1725
    cli_freelocks();
1684
1726
    free(engine);
1685
1727
}
1686
1728