~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/chmunpack.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#endif
34
34
#include <string.h>
35
35
 
36
 
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
37
 
#if HAVE_MMAP
38
 
#if HAVE_SYS_MMAN_H
39
 
#include <sys/mman.h>
40
 
#else /* HAVE_SYS_MMAN_H */
41
 
#undef HAVE_MMAP
42
 
#endif /* HAVE_SYS_MMAN_H */
43
 
#endif /* HAVE_MMAP */
44
 
#else/* PACKED */
45
 
#undef HAVE_MMAP
46
 
#endif
47
 
 
 
36
#include "fmap.h"
48
37
#include "others.h"
49
38
#include "mspack.h"
50
39
#include "cltypes.h"
63
52
#pragma pack 1
64
53
#endif
65
54
 
66
 
#ifndef O_BINARY
67
 
#define O_BINARY        0
68
 
#endif
69
 
 
70
55
#define CHM_CHUNK_HDR_LEN (0x14)
71
56
 
72
57
#define CHM_CONTROL_LEN (0x18)
117
102
#define chm_endian_convert_64(x) le64_to_host(x)
118
103
 
119
104
/* Read in a block of data from either the mmap area or the given fd */
120
 
static int chm_read_data(int fd, char *dest, off_t offset, off_t len,
121
 
                        char *m_area, off_t m_length)
 
105
static int chm_read_data(fmap_t *map, char *dest, off_t offset, off_t len)
122
106
{
123
 
        if ((offset < 0) || (len < 0) || ((offset+len) < 0)) {
124
 
                return FALSE;
125
 
        }
126
 
        if (m_area != NULL) {
127
 
                if ((offset+len) > m_length) {
128
 
                        return FALSE;
129
 
                }
130
 
                memcpy(dest, m_area+offset, len);
131
 
        } else {
132
 
                if (lseek(fd, offset, SEEK_SET) != offset) {
133
 
                        return FALSE;
134
 
                }
135
 
                if (cli_readn(fd, dest, len) != len) {
136
 
                        return FALSE;
137
 
                }
138
 
        }
139
 
        return TRUE;
 
107
    void *src = fmap_need_off_once(map, offset, len);
 
108
    if(!src) return FALSE;
 
109
    memcpy(dest, src, len);
 
110
    return TRUE;
140
111
}
141
112
 
142
113
static uint64_t chm_copy_file_data(int ifd, int ofd, uint64_t len)
182
153
        }
183
154
}
184
155
 
185
 
static int itsf_read_header(int fd, chm_itsf_header_t *itsf_hdr, char *m_area, off_t m_length)
 
156
static int itsf_read_header(chm_metadata_t *metadata)
186
157
{
187
 
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
188
 
        if (!chm_read_data(fd, (char *) itsf_hdr, 0, CHM_ITSF_MIN_LEN,
189
 
                                m_area, m_length)) {
190
 
                return FALSE;
191
 
        }
192
 
#else
193
 
        if (cli_readn(fd, &itsf_hdr->signature, 4) != 4) {
194
 
                return FALSE;
195
 
        }
196
 
        if (cli_readn(fd, &itsf_hdr->version, 4) != 4) {
197
 
                return FALSE;
198
 
        }
199
 
        if (cli_readn(fd, &itsf_hdr->header_len, 4) != 4) {
200
 
                return FALSE;
201
 
        }
202
 
        if (cli_readn(fd, &itsf_hdr->unknown, 4) != 4) {
203
 
                return FALSE;
204
 
        }
205
 
        if (cli_readn(fd, &itsf_hdr->last_modified, 4) != 4) {
206
 
                return FALSE;
207
 
        }
208
 
        if (cli_readn(fd, &itsf_hdr->lang_id, 4) != 4) {
209
 
                return FALSE;
210
 
        }
211
 
        if (cli_readn(fd, &itsf_hdr->dir_clsid, 16) != 16) {
212
 
                return FALSE;
213
 
        }
214
 
        if (cli_readn(fd, &itsf_hdr->stream_clsid, 16) != 16) {
215
 
                return FALSE;
216
 
        }
217
 
        if (cli_readn(fd, &itsf_hdr->sec0_offset, 8) != 8) {
218
 
                return FALSE;
219
 
        }
220
 
        if (cli_readn(fd, &itsf_hdr->sec0_len, 8) != 8) {
221
 
                return FALSE;
222
 
        }
223
 
        if (cli_readn(fd, &itsf_hdr->dir_offset, 8) != 8) {
224
 
                return FALSE;
225
 
        }
226
 
        if (cli_readn(fd, &itsf_hdr->dir_len, 8) != 8) {
227
 
                return FALSE;
228
 
        }
229
 
        if (itsf_hdr->version > 2) {
230
 
                if (cli_readn(fd, &itsf_hdr->data_offset, 8) != 8) {
231
 
                        return FALSE;
232
 
                }
233
 
        }
234
 
#endif
 
158
        chm_itsf_header_t *itsf_hdr = &metadata->itsf_hdr;
 
159
        if (!chm_read_data(metadata->map, (char *)itsf_hdr, 0, CHM_ITSF_MIN_LEN))
 
160
                return FALSE;
235
161
        if (memcmp(itsf_hdr->signature, "ITSF", 4) != 0) {
236
162
                cli_dbgmsg("ITSF signature mismatch\n");
237
163
                return FALSE;
270
196
        cli_dbgmsg("Lang ID:\t%u\n\n", itsp_hdr->lang_id);
271
197
}
272
198
 
273
 
static int itsp_read_header(int fd, chm_itsp_header_t *itsp_hdr, off_t offset,
274
 
                                char *m_area, off_t m_length)
 
199
static int itsp_read_header(chm_metadata_t *metadata, off_t offset)
275
200
{
276
 
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
277
 
        if (!chm_read_data(fd, (char *) itsp_hdr, offset, CHM_ITSP_LEN,
278
 
                                m_area, m_length)) {
279
 
                return FALSE;
280
 
        }
281
 
#else
282
 
        if (lseek(fd, offset, SEEK_SET) != offset) {
283
 
                return FALSE;
284
 
        }
285
 
        if (cli_readn(fd, &itsp_hdr->signature, 4) != 4) {
286
 
                return FALSE;
287
 
        }
288
 
        if (cli_readn(fd, &itsp_hdr->version, 4) != 4) {
289
 
                return FALSE;
290
 
        }
291
 
        if (cli_readn(fd, &itsp_hdr->header_len, 4) != 4) {
292
 
                return FALSE;
293
 
        }
294
 
        if (cli_readn(fd, &itsp_hdr->unknown1, 4) != 4) {
295
 
                return FALSE;
296
 
        }
297
 
        if (cli_readn(fd, &itsp_hdr->block_len, 4) != 4) {
298
 
                return FALSE;
299
 
        }
300
 
        if (cli_readn(fd, &itsp_hdr->blockidx_intvl, 4) != 4) {
301
 
                return FALSE;
302
 
        }
303
 
        if (cli_readn(fd, &itsp_hdr->index_depth, 4) != 4) {
304
 
                return FALSE;
305
 
        }
306
 
        if (cli_readn(fd, &itsp_hdr->index_root, 4) != 4) {
307
 
                return FALSE;
308
 
        }
309
 
        if (cli_readn(fd, &itsp_hdr->index_head, 4) != 4) {
310
 
                return FALSE;
311
 
        }
312
 
        if (cli_readn(fd, &itsp_hdr->index_tail, 4) != 4) {
313
 
                return FALSE;
314
 
        }
315
 
        if (cli_readn(fd, &itsp_hdr->unknown2, 4) != 4) {
316
 
                return FALSE;
317
 
        }
318
 
        if (cli_readn(fd, &itsp_hdr->num_blocks, 4) != 4) {
319
 
                return FALSE;
320
 
        }
321
 
        if (cli_readn(fd, &itsp_hdr->lang_id, 4) != 4) {
322
 
                return FALSE;
323
 
        }
324
 
        if (cli_readn(fd, &itsp_hdr->system_clsid, 16) != 16) {
325
 
                return FALSE;
326
 
        }
327
 
        if (cli_readn(fd, &itsp_hdr->unknown4, 16) != 16) {
328
 
                return FALSE;
329
 
        }
330
 
#endif
 
201
        chm_itsp_header_t *itsp_hdr = &metadata->itsp_hdr;
 
202
        if (!chm_read_data(metadata->map, (char *)itsp_hdr, offset, CHM_ITSP_LEN))
 
203
                return FALSE;
331
204
        if (memcmp(itsp_hdr->signature, "ITSP", 4) != 0) {
332
205
                cli_dbgmsg("ITSP signature mismatch\n");
333
206
                return FALSE;
417
290
        return TRUE;
418
291
}
419
292
 
420
 
static int prepare_file(int fd, chm_metadata_t *metadata)
 
293
static int prepare_file(chm_metadata_t *metadata)
421
294
{
422
295
        uint64_t name_len, section;
423
296
 
445
318
        return CL_BREAK;
446
319
}
447
320
 
448
 
static int read_chunk(chm_metadata_t *metadata, int fd)
 
321
static int read_chunk(chm_metadata_t *metadata)
449
322
{
450
323
        cli_dbgmsg("in read_chunk\n");
451
324
 
453
326
                return CL_EFORMAT;
454
327
        }
455
328
 
456
 
        if (metadata->m_area != NULL) {
457
 
                if (metadata->chunk_offset > metadata->m_length) {
458
 
                        return CL_EFORMAT;
459
 
                }
460
 
                if ((metadata->chunk_offset + metadata->itsp_hdr.block_len) > metadata->m_length) {
461
 
                        return CL_EFORMAT;
462
 
                }
463
 
                metadata->chunk_data = metadata->m_area + metadata->chunk_offset;
 
329
        if (metadata->chunk_offset > metadata->m_length) {
 
330
                return CL_EFORMAT;
 
331
        }
 
332
        if ((metadata->chunk_offset + metadata->itsp_hdr.block_len) > metadata->m_length) {
 
333
                return CL_EFORMAT;
 
334
        }
 
335
        metadata->chunk_data = fmap_need_off_once(metadata->map, metadata->chunk_offset, metadata->itsp_hdr.block_len);
 
336
        if(!metadata->chunk_data) return CL_EFORMAT;
464
337
 
465
 
        } else {
466
 
                if (!metadata->chunk_data) {
467
 
                        metadata->chunk_data = (char *) cli_malloc(metadata->itsp_hdr.block_len);
468
 
                        if (!metadata->chunk_data) {
469
 
                                return CL_EMEM;
470
 
                        }
471
 
                }
472
 
                if (lseek(fd, metadata->chunk_offset, SEEK_SET) != metadata->chunk_offset) {
473
 
                        goto abort;
474
 
                }
475
 
                if ((uint32_t) cli_readn(fd, metadata->chunk_data, metadata->itsp_hdr.block_len) != metadata->itsp_hdr.block_len) {
476
 
                        goto abort;
477
 
                }
478
 
        }
479
338
        metadata->chunk_current = metadata->chunk_data + CHM_CHUNK_HDR_LEN;
480
339
        metadata->chunk_end = metadata->chunk_data + metadata->itsp_hdr.block_len;
481
340
 
483
342
                metadata->chunk_entries = (uint16_t)((((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-2] << 0)
484
343
                                        | (((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-1] << 8));
485
344
        } else if (memcmp(metadata->chunk_data, "PMGI", 4) != 0) {
486
 
                if (!metadata->m_area && metadata->chunk_data) {
487
 
                        free(metadata->chunk_data);
488
 
                }
489
345
                return CL_BREAK;
490
346
        }
491
347
 
492
348
        return CL_SUCCESS;
493
 
abort:
494
 
        if (!metadata->m_area && metadata->chunk_data) {
495
 
                free(metadata->chunk_data);
496
 
                metadata->chunk_data = NULL;
497
 
        }
498
 
        return CL_EFORMAT;
499
349
}
500
350
 
501
351
static void print_sys_control(lzx_control_t *lzx_control)
514
364
        cli_dbgmsg("Cache Size:\t%d\n\n", lzx_control->cache_size);
515
365
}
516
366
 
517
 
static int read_sys_control(int fd, chm_metadata_t *metadata, lzx_control_t *lzx_control)
 
367
static int read_sys_control(chm_metadata_t *metadata, lzx_control_t *lzx_control)
518
368
{
519
369
        off_t offset;
520
370
        
526
376
                return FALSE;
527
377
        }
528
378
 
529
 
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
530
 
        if (!chm_read_data(fd, (char *) lzx_control, offset, CHM_CONTROL_LEN,
531
 
                                metadata->m_area, metadata->m_length)) {
532
 
                return FALSE;
533
 
        }
534
 
#else
535
 
        if (lseek(fd, offset, SEEK_SET) != offset) {
536
 
                return FALSE;
537
 
        }
538
 
        if (cli_readn(fd, &lzx_control->length, 4) != 4) {
539
 
                return FALSE;
540
 
        }
541
 
        if (cli_readn(fd, &lzx_control->signature, 4) != 4) {
542
 
                return FALSE;
543
 
        }
544
 
        if (cli_readn(fd, &lzx_control->version, 4) != 4) {
545
 
                return FALSE;
546
 
        }
547
 
        if (cli_readn(fd, &lzx_control->reset_interval, 4) != 4) {
548
 
                return FALSE;
549
 
        }
550
 
        if (cli_readn(fd, &lzx_control->window_size, 4) != 4) {
551
 
                return FALSE;
552
 
        }
553
 
        if (cli_readn(fd, &lzx_control->cache_size, 4) != 4) {
554
 
                return FALSE;
555
 
        }
556
 
#endif
 
379
        if (!chm_read_data(metadata->map, (char *) lzx_control, offset, CHM_CONTROL_LEN)) {
 
380
                return FALSE;
 
381
        }
 
382
 
557
383
        lzx_control->length = chm_endian_convert_32(lzx_control->length);
558
384
        lzx_control->version = chm_endian_convert_32(lzx_control->version);
559
385
        lzx_control->reset_interval = chm_endian_convert_32(lzx_control->reset_interval);
591
417
        cli_dbgmsg("Length:\t%lu\n\n", (unsigned long int) lzx_content->length);
592
418
}
593
419
 
594
 
static int read_sys_content(int fd, chm_metadata_t *metadata, lzx_content_t *lzx_content)
 
420
static int read_sys_content(chm_metadata_t *metadata, lzx_content_t *lzx_content)
595
421
{
596
422
        lzx_content->offset = metadata->itsf_hdr.data_offset + metadata->sys_content.offset;
597
423
        lzx_content->length = metadata->sys_content.length;
615
441
        cli_dbgmsg("Frame Len:\t%lu\n\n", (unsigned long int) lzx_reset_table->frame_len);
616
442
}
617
443
 
618
 
static int read_sys_reset_table(int fd, chm_metadata_t *metadata, lzx_reset_table_t *lzx_reset_table)
 
444
static int read_sys_reset_table(chm_metadata_t *metadata, lzx_reset_table_t *lzx_reset_table)
619
445
{
620
446
        off_t offset;
621
447
 
632
458
        /* Save the entry offset for later use */
633
459
        lzx_reset_table->rt_offset = offset-4;
634
460
 
635
 
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
636
 
        if (!chm_read_data(fd, (char *) lzx_reset_table, offset, CHM_RESET_TABLE_LEN,
637
 
                                metadata->m_area, metadata->m_length)) {
638
 
                return FALSE;
639
 
        }
640
 
#else   
641
 
        if (lseek(fd, offset, SEEK_SET) != offset) {
642
 
                return FALSE;
643
 
        }
644
 
        if (cli_readn(fd, &lzx_reset_table->num_entries, 4) != 4) {
645
 
                return FALSE;
646
 
        }
647
 
        if (cli_readn(fd, &lzx_reset_table->entry_size, 4) != 4) {
648
 
                return FALSE;
649
 
        }
650
 
        if (cli_readn(fd, &lzx_reset_table->table_offset, 4) != 4) {
651
 
                return FALSE;
652
 
        }
653
 
        if (cli_readn(fd, &lzx_reset_table->uncom_len, 8) != 8) {
654
 
                return FALSE;
655
 
        }
656
 
        if (cli_readn(fd, &lzx_reset_table->com_len, 8) != 8) {
657
 
                return FALSE;
658
 
        }
659
 
        if (cli_readn(fd, &lzx_reset_table->frame_len, 8) != 8) {
660
 
                return FALSE;
661
 
        }
662
 
#endif
 
461
        if (!chm_read_data(metadata->map, (char *) lzx_reset_table, offset, CHM_RESET_TABLE_LEN)) {
 
462
                return FALSE;
 
463
        }
 
464
 
663
465
        lzx_reset_table->num_entries = chm_endian_convert_32(lzx_reset_table->num_entries);
664
466
        lzx_reset_table->entry_size = chm_endian_convert_32(lzx_reset_table->entry_size);
665
467
        lzx_reset_table->table_offset = chm_endian_convert_32(lzx_reset_table->table_offset);
693
495
        char filename[1024];
694
496
        struct cab_file file;
695
497
        
696
 
        snprintf(filename, 1024, "%s/clamav-unchm.bin", dirname);
 
498
        snprintf(filename, 1024, "%s"PATHSEP"clamav-unchm.bin", dirname);
697
499
        tmpfd = open(filename, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU);
698
500
        if (tmpfd<0) {
699
501
                cli_dbgmsg("open failed for %s\n", filename);
705
507
                goto abort;
706
508
        }
707
509
 
708
 
        if (!read_sys_control(fd, metadata, &lzx_control)) {
709
 
                goto abort;
710
 
        }
711
 
        if (!read_sys_content(fd, metadata, &lzx_content)) {
712
 
                goto abort;
713
 
        }
714
 
        if (!read_sys_reset_table(fd, metadata, &lzx_reset_table)) {
 
510
        if (!read_sys_control(metadata, &lzx_control)) {
 
511
                goto abort;
 
512
        }
 
513
        if (!read_sys_content(metadata, &lzx_content)) {
 
514
                goto abort;
 
515
        }
 
516
        if (!read_sys_reset_table(metadata, &lzx_reset_table)) {
715
517
                goto abort;
716
518
        }
717
519
        
769
571
        lzx_decompress(stream, length);
770
572
        lzx_free(stream);
771
573
        
772
 
#ifndef C_WINDOWS
 
574
#ifndef _WIN32
773
575
        /* Delete the file */
774
576
        if(cli_unlink(filename))
775
577
                retval = -1;
793
595
        }
794
596
        
795
597
        metadata->sys_control.length = metadata->sys_content.length = metadata->sys_reset.length = 0;
796
 
        metadata->m_area = NULL;
 
598
        metadata->map = NULL;
797
599
        metadata->ufd = -1;
798
600
        metadata->num_chunks = metadata->chunk_entries = 0;
799
601
        metadata->chunk_data = NULL;
805
607
        if (metadata->ufd >= 0) {
806
608
                close(metadata->ufd);
807
609
        }
808
 
        if (!metadata->m_area && metadata->chunk_data) {
809
 
                free(metadata->chunk_data);
810
 
        }
811
 
#ifdef HAVE_MMAP
812
 
        if (metadata->m_area) {
813
 
                munmap(metadata->m_area, metadata->m_length);
814
 
        }
815
 
#endif
 
610
        funmap(metadata->map);
816
611
}
817
612
 
818
 
int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata, cli_ctx *ctx)
 
613
int cli_chm_extract_file(char *dirname, chm_metadata_t *metadata, cli_ctx *ctx)
819
614
{
820
615
        char filename[1024];
821
616
        uint64_t len;
826
621
                cli_dbgmsg("seek in uncompressed stream failed\n");
827
622
                return CL_EFORMAT;
828
623
        }
829
 
        snprintf(filename, 1024, "%s/%lu.chm", dirname, (unsigned long int) metadata->file_offset);
 
624
        snprintf(filename, 1024, "%s"PATHSEP"%lu.chm", dirname, (unsigned long int) metadata->file_offset);
830
625
        metadata->ofd = open(filename, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU);
831
626
        if (metadata->ofd < 0) {
832
627
                return CL_ECREAT;
841
636
        return CL_SUCCESS;
842
637
}       
843
638
 
844
 
int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata)
 
639
int cli_chm_prepare_file(chm_metadata_t *metadata)
845
640
{
846
641
        int retval;
847
642
        
852
647
                        if (metadata->num_chunks == 0) {
853
648
                                return CL_BREAK;
854
649
                        }
855
 
                        if ((retval = read_chunk(metadata, fd)) != CL_SUCCESS) {
 
650
                        if ((retval = read_chunk(metadata)) != CL_SUCCESS) {
856
651
                                return retval;
857
652
                        }
858
653
                        metadata->num_chunks--;
859
654
                        metadata->chunk_offset += metadata->itsp_hdr.block_len;
860
655
                }
861
 
                retval = prepare_file(fd, metadata);
 
656
                retval = prepare_file(metadata);
862
657
        } while (retval == CL_BREAK); /* Ran out of chunk entries before finding a file */
863
658
        return retval;
864
659
}
874
669
                return retval;
875
670
        }
876
671
 
877
 
#ifdef HAVE_MMAP
878
672
        if (fstat(fd, &statbuf) == 0) {
879
673
                if (statbuf.st_size < CHM_ITSF_MIN_LEN) {
880
 
                        goto abort;
 
674
                        return CL_ESTAT;
881
675
                }
882
676
                metadata->m_length = statbuf.st_size;
883
 
                metadata->m_area = (char *) mmap(NULL, metadata->m_length, PROT_READ, MAP_PRIVATE, fd, 0);
884
 
                if (metadata->m_area == MAP_FAILED) {
885
 
                        metadata->m_area = NULL;
 
677
                metadata->map = fmap(fd, 0, metadata->m_length);
 
678
                if (!metadata->map) {
 
679
                        return CL_EMAP;
886
680
                }
887
681
        }
888
 
#endif
889
682
 
890
 
        if (!itsf_read_header(fd, &metadata->itsf_hdr, metadata->m_area, metadata->m_length)) {
 
683
        if (!itsf_read_header(metadata)) {
891
684
                goto abort;
892
685
        }
893
686
        itsf_print_header(&metadata->itsf_hdr);
894
687
 
895
 
        if (!itsp_read_header(fd, &metadata->itsp_hdr, metadata->itsf_hdr.dir_offset, metadata->m_area, metadata->m_length)) {
 
688
        if (!itsp_read_header(metadata, metadata->itsf_hdr.dir_offset)) {
896
689
                goto abort;
897
690
        }
898
691
        itsp_print_header(&metadata->itsp_hdr);
916
709
        }
917
710
        
918
711
        while (metadata->num_chunks) {
919
 
                if (read_chunk(metadata, fd) != CL_SUCCESS) {
 
712
                if (read_chunk(metadata) != CL_SUCCESS) {
920
713
                        cli_dbgmsg("read_chunk failed\n");
921
714
                        goto abort;
922
715
                }
945
738
        return CL_SUCCESS;
946
739
 
947
740
abort:
948
 
#ifdef HAVE_MMAP
949
 
        if (metadata->m_area) {
950
 
                munmap(metadata->m_area, metadata->m_length);
951
 
        }
952
 
#endif
 
741
        funmap(metadata->map);
953
742
        return CL_EFORMAT;
954
743
}