lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

003-CVE-2014-8141-getzip64data.patch (4918B)


      1 --- a/fileio.c
      2 +++ b/fileio.c
      3 @@ -176,6 +176,8 @@ static ZCONST char Far FilenameTooLongTr
      4  #endif
      5  static ZCONST char Far ExtraFieldTooLong[] =
      6    "warning:  extra field too long (%d).  Ignoring...\n";
      7 +static ZCONST char Far ExtraFieldCorrupt[] =
      8 +  "warning:  extra field (type: 0x%04x) corrupt.  Continuing...\n";
      9  
     10  #ifdef WINDLL
     11     static ZCONST char Far DiskFullQuery[] =
     12 @@ -2295,7 +2297,12 @@ int do_string(__G__ length, option)   /*
     13              if (readbuf(__G__ (char *)G.extra_field, length) == 0)
     14                  return PK_EOF;
     15              /* Looks like here is where extra fields are read */
     16 -            getZip64Data(__G__ G.extra_field, length);
     17 +            if (getZip64Data(__G__ G.extra_field, length) != PK_COOL)
     18 +            {
     19 +                Info(slide, 0x401, ((char *)slide,
     20 +                 LoadFarString( ExtraFieldCorrupt), EF_PKSZ64));
     21 +                error = PK_WARN;
     22 +            }
     23  #ifdef UNICODE_SUPPORT
     24              G.unipath_filename = NULL;
     25              if (G.UzO.U_flag < 2) {
     26 --- a/process.c
     27 +++ b/process.c
     28 @@ -1,5 +1,5 @@
     29  /*
     30 -  Copyright (c) 1990-2009 Info-ZIP.  All rights reserved.
     31 +  Copyright (c) 1990-2014 Info-ZIP.  All rights reserved.
     32  
     33    See the accompanying file LICENSE, version 2009-Jan-02 or later
     34    (the contents of which are also included in unzip.h) for terms of use.
     35 @@ -1888,48 +1888,82 @@ int getZip64Data(__G__ ef_buf, ef_len)
     36      and a 4-byte version of disk start number.
     37      Sets both local header and central header fields.  Not terribly clever,
     38      but it means that this procedure is only called in one place.
     39 +
     40 +    2014-12-05 SMS.
     41 +    Added checks to ensure that enough data are available before calling
     42 +    makeint64() or makelong().  Replaced various sizeof() values with
     43 +    simple ("4" or "8") constants.  (The Zip64 structures do not depend
     44 +    on our variable sizes.)  Error handling is crude, but we should now
     45 +    stay within the buffer.
     46    ---------------------------------------------------------------------------*/
     47  
     48 +#define Z64FLGS 0xffff
     49 +#define Z64FLGL 0xffffffff
     50 +
     51      if (ef_len == 0 || ef_buf == NULL)
     52          return PK_COOL;
     53  
     54      Trace((stderr,"\ngetZip64Data: scanning extra field of length %u\n",
     55        ef_len));
     56  
     57 -    while (ef_len >= EB_HEADSIZE) {
     58 +    while (ef_len >= EB_HEADSIZE)
     59 +    {
     60          eb_id = makeword(EB_ID + ef_buf);
     61          eb_len = makeword(EB_LEN + ef_buf);
     62  
     63 -        if (eb_len > (ef_len - EB_HEADSIZE)) {
     64 -            /* discovered some extra field inconsistency! */
     65 +        if (eb_len > (ef_len - EB_HEADSIZE))
     66 +        {
     67 +            /* Extra block length exceeds remaining extra field length. */
     68              Trace((stderr,
     69                "getZip64Data: block length %u > rest ef_size %u\n", eb_len,
     70                ef_len - EB_HEADSIZE));
     71              break;
     72          }
     73 -        if (eb_id == EF_PKSZ64) {
     74 -
     75 +        if (eb_id == EF_PKSZ64)
     76 +        {
     77            int offset = EB_HEADSIZE;
     78  
     79 -          if (G.crec.ucsize == 0xffffffff || G.lrec.ucsize == 0xffffffff){
     80 -            G.lrec.ucsize = G.crec.ucsize = makeint64(offset + ef_buf);
     81 -            offset += sizeof(G.crec.ucsize);
     82 +          if ((G.crec.ucsize == Z64FLGL) || (G.lrec.ucsize == Z64FLGL))
     83 +          {
     84 +            if (offset+ 8 > ef_len)
     85 +              return PK_ERR;
     86 +
     87 +            G.crec.ucsize = G.lrec.ucsize = makeint64(offset + ef_buf);
     88 +            offset += 8;
     89            }
     90 -          if (G.crec.csize == 0xffffffff || G.lrec.csize == 0xffffffff){
     91 -            G.csize = G.lrec.csize = G.crec.csize = makeint64(offset + ef_buf);
     92 -            offset += sizeof(G.crec.csize);
     93 +
     94 +          if ((G.crec.csize == Z64FLGL) || (G.lrec.csize == Z64FLGL))
     95 +          {
     96 +            if (offset+ 8 > ef_len)
     97 +              return PK_ERR;
     98 +
     99 +            G.csize = G.crec.csize = G.lrec.csize = makeint64(offset + ef_buf);
    100 +            offset += 8;
    101            }
    102 -          if (G.crec.relative_offset_local_header == 0xffffffff){
    103 +
    104 +          if (G.crec.relative_offset_local_header == Z64FLGL)
    105 +          {
    106 +            if (offset+ 8 > ef_len)
    107 +              return PK_ERR;
    108 +
    109              G.crec.relative_offset_local_header = makeint64(offset + ef_buf);
    110 -            offset += sizeof(G.crec.relative_offset_local_header);
    111 +            offset += 8;
    112            }
    113 -          if (G.crec.disk_number_start == 0xffff){
    114 +
    115 +          if (G.crec.disk_number_start == Z64FLGS)
    116 +          {
    117 +            if (offset+ 4 > ef_len)
    118 +              return PK_ERR;
    119 +
    120              G.crec.disk_number_start = (zuvl_t)makelong(offset + ef_buf);
    121 -            offset += sizeof(G.crec.disk_number_start);
    122 +            offset += 4;
    123            }
    124 +#if 0
    125 +          break;                /* Expect only one EF_PKSZ64 block. */
    126 +#endif /* 0 */
    127          }
    128  
    129 -        /* Skip this extra field block */
    130 +        /* Skip this extra field block. */
    131          ef_buf += (eb_len + EB_HEADSIZE);
    132          ef_len -= (eb_len + EB_HEADSIZE);
    133      }