123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- $OpenBSD: patch-process_c,v 1.3 2017/03/23 17:26:17 bluhm Exp $
- Fix: handle the PKWare verification bit of internal attributes
- https://bugs.debian.org/630078
- Fix: extraction of symlinks
- Fix CVE-2014-8141: out-of-bounds read issues in getZip64Data()
- Fix: do not ignore extra fields containing Unix Timestamps
- https://bugs.debian.org/842993
- Fix: restore uid and gid information when requested
- https://bugs.debian.org/689212
- --- process.c.orig Fri Mar 6 02:25:10 2009
- +++ process.c Tue Mar 21 16:10:27 2017
- @@ -1,5 +1,5 @@
- /*
- - Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
- + Copyright (c) 1990-2014 Info-ZIP. All rights reserved.
-
- See the accompanying file LICENSE, version 2009-Jan-02 or later
- (the contents of which are also included in unzip.h) for terms of use.
- @@ -1729,6 +1729,13 @@ int process_cdir_file_hdr(__G) /* return PK-type er
- else if (uO.L_flag > 1) /* let -LL force lower case for all names */
- G.pInfo->lcflag = 1;
-
- + /* Handle the PKWare verification bit, bit 2 (0x0004) of internal
- + attributes. If this is set, then a verification checksum is in the
- + first 3 bytes of the external attributes. In this case all we can use
- + for setting file attributes is the last external attributes byte. */
- + if (G.crec.internal_file_attributes & 0x0004)
- + G.crec.external_file_attributes &= (ulg)0xff;
- +
- /* do Amigas (AMIGA_) also have volume labels? */
- if (IS_VOLID(G.crec.external_file_attributes) &&
- (G.pInfo->hostnum == FS_FAT_ || G.pInfo->hostnum == FS_HPFS_ ||
- @@ -1751,6 +1758,12 @@ int process_cdir_file_hdr(__G) /* return PK-type er
- = (G.crec.general_purpose_bit_flag & (1 << 11)) == (1 << 11);
- #endif
-
- +#ifdef SYMLINKS
- + /* Initialize the symlink flag, may be set by the platform-specific
- + mapattr function. */
- + G.pInfo->symlink = 0;
- +#endif
- +
- return PK_COOL;
-
- } /* end function process_cdir_file_hdr() */
- @@ -1888,48 +1901,82 @@ int getZip64Data(__G__ ef_buf, ef_len)
- and a 4-byte version of disk start number.
- Sets both local header and central header fields. Not terribly clever,
- but it means that this procedure is only called in one place.
- +
- + 2014-12-05 SMS.
- + Added checks to ensure that enough data are available before calling
- + makeint64() or makelong(). Replaced various sizeof() values with
- + simple ("4" or "8") constants. (The Zip64 structures do not depend
- + on our variable sizes.) Error handling is crude, but we should now
- + stay within the buffer.
- ---------------------------------------------------------------------------*/
-
- +#define Z64FLGS 0xffff
- +#define Z64FLGL 0xffffffff
- +
- if (ef_len == 0 || ef_buf == NULL)
- return PK_COOL;
-
- Trace((stderr,"\ngetZip64Data: scanning extra field of length %u\n",
- ef_len));
-
- - while (ef_len >= EB_HEADSIZE) {
- + while (ef_len >= EB_HEADSIZE)
- + {
- eb_id = makeword(EB_ID + ef_buf);
- eb_len = makeword(EB_LEN + ef_buf);
-
- - if (eb_len > (ef_len - EB_HEADSIZE)) {
- - /* discovered some extra field inconsistency! */
- + if (eb_len > (ef_len - EB_HEADSIZE))
- + {
- + /* Extra block length exceeds remaining extra field length. */
- Trace((stderr,
- "getZip64Data: block length %u > rest ef_size %u\n", eb_len,
- ef_len - EB_HEADSIZE));
- break;
- }
- - if (eb_id == EF_PKSZ64) {
- -
- + if (eb_id == EF_PKSZ64)
- + {
- int offset = EB_HEADSIZE;
-
- - if (G.crec.ucsize == 0xffffffff || G.lrec.ucsize == 0xffffffff){
- - G.lrec.ucsize = G.crec.ucsize = makeint64(offset + ef_buf);
- - offset += sizeof(G.crec.ucsize);
- + if ((G.crec.ucsize == Z64FLGL) || (G.lrec.ucsize == Z64FLGL))
- + {
- + if (offset+ 8 > ef_len)
- + return PK_ERR;
- +
- + G.crec.ucsize = G.lrec.ucsize = makeint64(offset + ef_buf);
- + offset += 8;
- }
- - if (G.crec.csize == 0xffffffff || G.lrec.csize == 0xffffffff){
- - G.csize = G.lrec.csize = G.crec.csize = makeint64(offset + ef_buf);
- - offset += sizeof(G.crec.csize);
- +
- + if ((G.crec.csize == Z64FLGL) || (G.lrec.csize == Z64FLGL))
- + {
- + if (offset+ 8 > ef_len)
- + return PK_ERR;
- +
- + G.csize = G.crec.csize = G.lrec.csize = makeint64(offset + ef_buf);
- + offset += 8;
- }
- - if (G.crec.relative_offset_local_header == 0xffffffff){
- +
- + if (G.crec.relative_offset_local_header == Z64FLGL)
- + {
- + if (offset+ 8 > ef_len)
- + return PK_ERR;
- +
- G.crec.relative_offset_local_header = makeint64(offset + ef_buf);
- - offset += sizeof(G.crec.relative_offset_local_header);
- + offset += 8;
- }
- - if (G.crec.disk_number_start == 0xffff){
- +
- + if (G.crec.disk_number_start == Z64FLGS)
- + {
- + if (offset+ 4 > ef_len)
- + return PK_ERR;
- +
- G.crec.disk_number_start = (zuvl_t)makelong(offset + ef_buf);
- - offset += sizeof(G.crec.disk_number_start);
- + offset += 4;
- }
- +#if 0
- + break; /* Expect only one EF_PKSZ64 block. */
- +#endif /* 0 */
- }
-
- - /* Skip this extra field block */
- + /* Skip this extra field block. */
- ef_buf += (eb_len + EB_HEADSIZE);
- ef_len -= (eb_len + EB_HEADSIZE);
- }
- @@ -2867,10 +2914,13 @@ unsigned ef_scan_for_izux(ef_buf, ef_len, ef_is_c, dos
- break;
-
- case EF_IZUNIX2:
- - if (have_new_type_eb == 0) {
- - flags &= ~0x0ff; /* ignore any previous IZUNIX field */
- + if (have_new_type_eb == 0) { /* (< 1) */
- have_new_type_eb = 1;
- }
- + if (have_new_type_eb <= 1) {
- + /* Ignore any prior (EF_IZUNIX/EF_PKUNIX) UID/GID. */
- + flags &= 0x0ff;
- + }
- #ifdef IZ_HAVE_UXUIDGID
- if (have_new_type_eb > 1)
- break; /* IZUNIX3 overrides IZUNIX2 e.f. block ! */
- @@ -2886,6 +2936,8 @@ unsigned ef_scan_for_izux(ef_buf, ef_len, ef_is_c, dos
- /* new 3rd generation Unix ef */
- have_new_type_eb = 2;
-
- + /* Ignore any prior EF_IZUNIX/EF_PKUNIX/EF_IZUNIX2 UID/GID. */
- + flags &= 0x0ff;
- /*
- Version 1 byte version of this extra field, currently 1
- UIDSize 1 byte Size of UID field
- @@ -2897,7 +2949,7 @@ unsigned ef_scan_for_izux(ef_buf, ef_len, ef_is_c, dos
- #ifdef IZ_HAVE_UXUIDGID
- if (eb_len >= EB_UX3_MINLEN
- && z_uidgid != NULL
- - && (*((EB_HEADSIZE + 0) + ef_buf) == 1)
- + && (*((EB_HEADSIZE + 0) + ef_buf) == 1))
- /* only know about version 1 */
- {
- uch uid_size;
- @@ -2906,13 +2958,11 @@ unsigned ef_scan_for_izux(ef_buf, ef_len, ef_is_c, dos
- uid_size = *((EB_HEADSIZE + 1) + ef_buf);
- gid_size = *((EB_HEADSIZE + uid_size + 2) + ef_buf);
-
- - flags &= ~0x0ff; /* ignore any previous UNIX field */
- -
- if ( read_ux3_value((EB_HEADSIZE + 2) + ef_buf,
- - uid_size, z_uidgid[0])
- + uid_size, &z_uidgid[0])
- &&
- read_ux3_value((EB_HEADSIZE + uid_size + 3) + ef_buf,
- - gid_size, z_uidgid[1]) )
- + gid_size, &z_uidgid[1]) )
- {
- flags |= EB_UX2_VALID; /* signal success */
- }
|