~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to libclamunrar_iface/unrar_iface.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
204
204
static int is_rar_archive(int fd)
205
205
{
206
206
        mark_header_t mark;
207
 
        const mark_header_t rar_hdr[2] = {{0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00}, {'U', 'n', 'i', 'q', 'u', 'E', '!'}};
 
207
        const mark_header_t rar_hdr[2] = {{{0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00}}, {{'U', 'n', 'i', 'q', 'u', 'E', '!'}}};
208
208
 
209
209
 
210
210
    if(read(fd, &mark, SIZEOF_MARKHEAD) != SIZEOF_MARKHEAD)
264
264
    if(!is_rar_archive(fd))
265
265
        return UNRAR_ERR;
266
266
 
267
 
    unpack_data = (unpack_data_t *) malloc(sizeof(unpack_data_t));
268
 
    if(!unpack_data) {
269
 
        unrar_dbgmsg("UNRAR: malloc failed for unpack_data\n");
270
 
        return UNRAR_EMEM;
271
 
    }
272
 
    unpack_data->rarvm_data.mem = NULL;
273
 
    unpack_data->old_filter_lengths = NULL;
274
 
    unpack_data->PrgStack.array = unpack_data->Filters.array = NULL;
275
 
    unpack_data->PrgStack.num_items = unpack_data->Filters.num_items = 0;
276
 
    unpack_data->unp_crc = 0xffffffff;
277
 
 
278
 
    ppm_constructor(&unpack_data->ppm_data);
279
267
    main_hdr = read_header(fd, MAIN_HEAD);
280
 
    if(!main_hdr) {
281
 
        ppm_destructor(&unpack_data->ppm_data);
282
 
        rar_init_filters(unpack_data);
283
 
        unpack_free_data(unpack_data);
284
 
        free(unpack_data);
 
268
    if(!main_hdr)
285
269
        return UNRAR_ERR;
286
 
    }
 
270
 
287
271
    unrar_dbgmsg("UNRAR: Head CRC: %.4x\n", main_hdr->head_crc);
288
272
    unrar_dbgmsg("UNRAR: Head Type: %.2x\n", main_hdr->head_type);
289
273
    unrar_dbgmsg("UNRAR: Flags: %.4x\n", main_hdr->flags);
290
274
    unrar_dbgmsg("UNRAR: Head Size: %.4x\n", main_hdr->head_size);
291
275
 
 
276
    if(main_hdr->flags & MHD_PASSWORD) {
 
277
        free(main_hdr);
 
278
        return UNRAR_PASSWD;
 
279
    }
 
280
 
292
281
    snprintf(filename,1024,"%s/comments", dirname);
293
282
    if(mkdir(filename,0700)) {
294
283
        unrar_dbgmsg("UNRAR: Unable to create comment temporary directory\n");
295
284
        free(main_hdr);
296
 
        ppm_destructor(&unpack_data->ppm_data);
297
 
        rar_init_filters(unpack_data);
298
 
        unpack_free_data(unpack_data);
299
 
        free(unpack_data);
300
285
        return UNRAR_ERR;
301
286
    }
302
287
    state->comment_dir = strdup(filename);
303
288
    if(!state->comment_dir) {
304
289
        free(main_hdr);
305
 
        ppm_destructor(&unpack_data->ppm_data);
306
 
        rar_init_filters(unpack_data);
307
 
        unpack_free_data(unpack_data);
308
 
        free(unpack_data);
309
290
        return UNRAR_EMEM;
310
291
    }
311
292
 
312
293
    if(main_hdr->head_size < SIZEOF_NEWMHD) {
313
294
        free(main_hdr);
314
 
        ppm_destructor(&unpack_data->ppm_data);
315
 
        rar_init_filters(unpack_data);
316
 
        unpack_free_data(unpack_data);
317
 
        free(unpack_data);
318
295
        free(state->comment_dir);
319
296
        return UNRAR_ERR;
320
297
    }
321
298
 
 
299
    unpack_data = (unpack_data_t *) malloc(sizeof(unpack_data_t));
 
300
    if(!unpack_data) {
 
301
        free(main_hdr);
 
302
        free(state->comment_dir);
 
303
        unrar_dbgmsg("UNRAR: malloc failed for unpack_data\n");
 
304
        return UNRAR_EMEM;
 
305
    }
 
306
    unpack_data->rarvm_data.mem = NULL;
 
307
    unpack_data->old_filter_lengths = NULL;
 
308
    unpack_data->PrgStack.array = unpack_data->Filters.array = NULL;
 
309
    unpack_data->PrgStack.num_items = unpack_data->Filters.num_items = 0;
 
310
    unpack_data->unp_crc = 0xffffffff;
 
311
 
 
312
    ppm_constructor(&unpack_data->ppm_data);
 
313
 
322
314
    if(main_hdr->flags & MHD_COMMENT) {
323
315
        unrar_comment_header_t *comment_header;
324
316
        unrar_dbgmsg("UNRAR: RAR main comment\n");
387
379
        char filename[1024];
388
380
        int ofd;
389
381
        unrar_metadata_t *new_metadata;
390
 
        unpack_data_t *unpack_data;
391
382
 
392
383
 
393
384
    state->file_header = read_block(state->fd, FILE_HEAD);
542
533
    free(state->unpack_data);
543
534
    free(state->comment_dir);
544
535
}
 
536
 
 
537
#ifdef  C_WINDOWS
 
538
/*
 
539
 * A copy is needed here to avoid a cyclic dependancy libclamunrar_iface<->libclamav
 
540
 * e.g. see the comment in bug 775 about dropping the old internal snprintf
 
541
 * which didn't have this problem and bug 785
 
542
 */
 
543
#include <stdarg.h>
 
544
static int
 
545
snprintf(char *str, size_t size, const char *format, ...)
 
546
{
 
547
        int ret;
 
548
 
 
549
        va_list args;
 
550
        va_start(args, format);
 
551
        ret = _vsnprintf_s(str, size, _TRUNCATE, format, args);
 
552
        va_end(args);
 
553
        return ret;
 
554
}
 
555
#endif