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

« back to all changes in this revision

Viewing changes to libclamav/mbox.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:
30
30
#endif
31
31
#endif
32
32
 
33
 
#define _GNU_SOURCE
34
 
 
35
33
#include <stdio.h>
36
34
#include <stdlib.h>
37
35
#include <errno.h>
66
64
#include <pthread.h>
67
65
#endif
68
66
 
 
67
#include <openssl/ssl.h>
 
68
#include <openssl/err.h>
 
69
#include "libclamav/crypto.h"
 
70
 
69
71
#include "others.h"
70
72
#include "str.h"
71
73
#include "filetypes.h"
72
74
#include "mbox.h"
73
75
#include "dconf.h"
74
 
#include "md5.h"
75
76
#include "fmap.h"
76
77
 
77
78
#define DCONF_PHISHING mctx->ctx->dconf->phishing
1179
1180
                                break;
1180
1181
                        }
1181
1182
 
 
1183
            cli_chomp(boundary);
 
1184
 
1182
1185
                        /* Perhaps it should assume mixed? */
1183
1186
                        if(mimeSubtype[0] == '\0') {
1184
1187
                                cli_dbgmsg("Multipart has no subtype assuming alternative\n");
2135
2138
        char *out;
2136
2139
        int rc;
2137
2140
        char buf[RFC2821LENGTH + 1];
 
2141
    char *newline;
2138
2142
 
2139
2143
        if(line == NULL)
2140
2144
                return 0;       /* empty line */
2141
2145
        if(boundary == NULL)
2142
2146
                return 0;
2143
2147
 
2144
 
        /*cli_dbgmsg("boundaryStart: line = '%s' boundary = '%s'\n", line, boundary);*/
2145
 
 
2146
 
        if((*line != '-') && (*line != '('))
2147
 
                return 0;
2148
 
 
2149
 
        if(strchr(line, '-') == NULL)
2150
 
                return 0;
2151
 
 
2152
 
        if(strlen(line) <= sizeof(buf)) {
 
2148
    newline = strdup(line);
 
2149
    if (!(newline))
 
2150
        newline = line;
 
2151
 
 
2152
    if (newline != line && strlen(newline)) {
 
2153
        char *p;
 
2154
        /* Trim trailing spaces */
 
2155
        p = newline + strlen(newline)-1;
 
2156
        while (p >= newline && *p == ' ')
 
2157
            *(p--) = '\0';
 
2158
    }
 
2159
 
 
2160
    if (newline != line)
 
2161
        cli_chomp(newline);
 
2162
 
 
2163
        /* cli_dbgmsg("boundaryStart: line = '%s' boundary = '%s'\n", line, boundary); */
 
2164
 
 
2165
        if((*newline != '-') && (*newline != '(')) {
 
2166
        if (newline != line)
 
2167
            free(newline);
 
2168
                return 0;
 
2169
    }
 
2170
 
 
2171
        if(strchr(newline, '-') == NULL) {
 
2172
        if (newline != line)
 
2173
            free(newline);
 
2174
                return 0;
 
2175
    }
 
2176
 
 
2177
        if(strlen(newline) <= sizeof(buf)) {
2153
2178
                out = NULL;
2154
 
                ptr = rfc822comments(line, buf);
 
2179
                ptr = rfc822comments(newline, buf);
2155
2180
        } else
2156
 
                ptr = out = rfc822comments(line, NULL);
 
2181
                ptr = out = rfc822comments(newline, NULL);
2157
2182
 
2158
2183
        if(ptr == NULL)
2159
 
                ptr = line;
 
2184
                ptr = newline;
2160
2185
 
2161
2186
        if((*ptr++ != '-') || (*ptr == '\0')) {
2162
2187
                if(out)
2163
2188
                        free(out);
 
2189
        if (newline != line)
 
2190
            free(newline);
 
2191
 
2164
2192
                return 0;
2165
2193
        }
2166
2194
 
2184
2212
         * they're not. Irrespective of whatever RFC2822 says, we need to find
2185
2213
         * viruses in both types of mails.
2186
2214
         */
2187
 
        if((strstr(&ptr[1], boundary) != NULL) || (strstr(line, boundary) != NULL)) {
 
2215
        if((strstr(&ptr[1], boundary) != NULL) || (strstr(newline, boundary) != NULL)) {
2188
2216
                const char *k = ptr;
2189
2217
 
2190
2218
                /*
2219
2247
        if(rc == 1)
2220
2248
                cli_dbgmsg("boundaryStart: found %s in %s\n", boundary, line);
2221
2249
 
 
2250
    if (newline != line)
 
2251
        free(newline);
 
2252
 
2222
2253
        return rc;
2223
2254
}
2224
2255
 
2231
2262
boundaryEnd(const char *line, const char *boundary)
2232
2263
{
2233
2264
        size_t len;
 
2265
    char *newline, *p, *p2;
2234
2266
 
2235
2267
        if(line == NULL)
2236
2268
                return 0;
2237
2269
 
2238
 
        /*cli_dbgmsg("boundaryEnd: line = '%s' boundary = '%s'\n", line, boundary);*/
2239
 
 
2240
 
        if(*line++ != '-')
2241
 
                return 0;
2242
 
        if(*line++ != '-')
2243
 
                return 0;
 
2270
    p = newline = strdup(line);
 
2271
    if (!(newline)) {
 
2272
        p = newline = line;
 
2273
    }
 
2274
 
 
2275
    if (newline != line && strlen(newline)) {
 
2276
        /* Trim trailing spaces */
 
2277
        p2 = newline + strlen(newline)-1;
 
2278
        while (p2 >= newline && *p2 == ' ')
 
2279
            *(p2--) = '\0';
 
2280
    }
 
2281
 
 
2282
        /* cli_dbgmsg("boundaryEnd: line = '%s' boundary = '%s'\n", newline, boundary); */
 
2283
 
 
2284
        if(*p++ != '-') {
 
2285
        if (newline != line)
 
2286
            free(newline);
 
2287
                return 0;
 
2288
    }
 
2289
 
 
2290
        if(*p++ != '-') {
 
2291
        if (newline != line)
 
2292
            free(newline);
 
2293
 
 
2294
                return 0;
 
2295
    }
 
2296
 
2244
2297
        len = strlen(boundary);
2245
 
        if(strncasecmp(line, boundary, len) != 0)
 
2298
        if(strncasecmp(p, boundary, len) != 0) {
 
2299
        if (newline != line)
 
2300
            free(newline);
 
2301
 
2246
2302
                return 0;
 
2303
    }
2247
2304
        /*
2248
2305
         * Use < rather than == because some broken mails have white
2249
2306
         * space after the boundary
2250
2307
         */
2251
 
        if(strlen(line) < (len + 2))
2252
 
                return 0;
2253
 
        line = &line[len];
2254
 
        if(*line++ != '-')
2255
 
                return 0;
2256
 
        if(*line == '-') {
2257
 
                cli_dbgmsg("boundaryEnd: found %s in %s\n", boundary, line);
 
2308
        if(strlen(p) < (len + 2)) {
 
2309
        if (newline != line)
 
2310
            free(newline);
 
2311
 
 
2312
                return 0;
 
2313
    }
 
2314
 
 
2315
        p = &p[len];
 
2316
        if(*p++ != '-') {
 
2317
        if (newline != line)
 
2318
            free(newline);
 
2319
 
 
2320
                return 0;
 
2321
    }
 
2322
 
 
2323
        if(*p == '-') {
 
2324
                /* cli_dbgmsg("boundaryEnd: found %s in %s\n", boundary, p); */
 
2325
        if (newline != line)
 
2326
            free(newline);
 
2327
 
2258
2328
                return 1;
2259
2329
        }
 
2330
 
 
2331
    if (newline != line)
 
2332
        free(newline);
 
2333
 
2260
2334
        return 0;
2261
2335
}
2262
2336
 
2795
2869
        int n;
2796
2870
        char pdir[NAME_MAX + 1];
2797
2871
        unsigned char md5_val[16];
2798
 
        cli_md5_ctx md5;
2799
2872
        char *md5_hex;
2800
2873
 
2801
2874
        id = (char *)messageFindArgument(m, "id");
2852
2925
        }
2853
2926
 
2854
2927
        n = atoi(number);
2855
 
        cli_md5_init(&md5);
2856
 
        cli_md5_update(&md5, id, strlen(id));
2857
 
        cli_md5_final(md5_val, &md5);
 
2928
    cl_hash_data("md5", id, strlen(id), md5_val, NULL);
2858
2929
        md5_hex = cli_str2hex((const char*)md5_val, 16);
2859
2930
 
2860
2931
        if(!md5_hex) {