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

« back to all changes in this revision

Viewing changes to libclamav/prtn_intxn.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:
 
1
/*
 
2
 *  Copyright (C) 2014 Sourcefire, Inc.
 
3
 *
 
4
 *  Authors: Kevin Lin <klin@sourcefire.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License version 2 as
 
8
 *  published by the Free Software Foundation.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
 *  MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#if HAVE_CONFIG_H
 
22
#include "clamav-config.h"
 
23
#endif
 
24
 
 
25
#include <openssl/ssl.h>
 
26
#include <openssl/err.h>
 
27
#include "libclamav/crypto.h"
 
28
 
 
29
#include "cltypes.h"
 
30
#include "others.h"
 
31
#include "prtn_intxn.h"
 
32
 
 
33
static int prtn_intxn_list_is_empty(prtn_intxn_list_t* list)
 
34
{
 
35
    return (list->Head == NULL);
 
36
}
 
37
 
 
38
int prtn_intxn_list_init(prtn_intxn_list_t* list)
 
39
{
 
40
    list->Head = NULL;
 
41
    list->Size = 0;
 
42
    return CL_SUCCESS;
 
43
}
 
44
 
 
45
int prtn_intxn_list_check(prtn_intxn_list_t* list, unsigned *pitxn, off_t start, size_t size)
 
46
{
 
47
    prtn_intxn_node_t *new_node, *check_node;
 
48
    int ret = CL_CLEAN;
 
49
 
 
50
    *pitxn = list->Size;
 
51
 
 
52
    check_node = list->Head;
 
53
    while (check_node != NULL) {
 
54
        (*pitxn)--;
 
55
 
 
56
        if (start > check_node->Start) {
 
57
            if (check_node->Start+check_node->Size > start) {
 
58
                ret = CL_VIRUS;
 
59
                break;
 
60
            }
 
61
        }
 
62
        else if (start < check_node->Start) {
 
63
            if (start+size > check_node->Start) {
 
64
                ret = CL_VIRUS;
 
65
                break;
 
66
            }
 
67
        }
 
68
        else {
 
69
            ret = CL_VIRUS;
 
70
            break;
 
71
        }
 
72
 
 
73
        check_node = check_node->Next;
 
74
    }
 
75
 
 
76
    /* allocate new node for partition bounds */
 
77
    new_node = (prtn_intxn_node_t *) cli_malloc(sizeof(prtn_intxn_node_t));
 
78
    if (!new_node) {
 
79
        cli_dbgmsg("PRTN_INTXN: could not allocate new node for checklist!\n");
 
80
        prtn_intxn_list_free(list);
 
81
        return CL_EMEM;
 
82
    }
 
83
 
 
84
    new_node->Start = start;
 
85
    new_node->Size = size;
 
86
    new_node->Next = list->Head;
 
87
 
 
88
    list->Head = new_node;
 
89
    (list->Size)++;
 
90
    return ret;
 
91
}
 
92
 
 
93
int prtn_intxn_list_free(prtn_intxn_list_t* list)
 
94
{
 
95
    prtn_intxn_node_t *next = NULL;
 
96
 
 
97
    while (!prtn_intxn_list_is_empty(list)) {
 
98
        next = list->Head->Next;
 
99
 
 
100
        free(list->Head);
 
101
 
 
102
        list->Head = next;
 
103
        list->Size--;
 
104
    }
 
105
 
 
106
    return CL_SUCCESS;
 
107
}