Changeset 455 for trunk/src/minilzo.c


Ignore:
Timestamp:
Jun 29, 2014, 7:35:55 AM (10 years ago)
Author:
katerina
Message:

Fix for ticket #354 (LZO vulnerability, does not affect samhain).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/minilzo.c

    r1 r455  
    23992399#  endif
    24002400#  if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2)
    2401 #    define NEED_IP(x) \
    2402             if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x))  goto input_overrun
     2401#    define NEED_IP(x, y) \
     2402    if ( ((y > 0) && (x > (LZO_UINT_MAX - y))) || ((lzo_uint)(ip_end - ip) < (lzo_uint)((x)+(y))) )  goto input_overrun
    24032403#  endif
    24042404#endif
     
    24102410#  if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2)
    24112411#    undef TEST_OP
    2412 #    define NEED_OP(x) \
    2413             if ((lzo_uint)(op_end - op) < (lzo_uint)(x))  goto output_overrun
     2412#    define NEED_OP(x,y) \
     2413    if (  ((y > 0) && (x > (LZO_UINT_MAX - y))) || ((lzo_uint)(op_end - op) < (lzo_uint)((x)+(y))) )  goto output_overrun
    24142414#  endif
    24152415#endif
     
    24392439#  define HAVE_NEED_IP
    24402440#else
    2441 #  define NEED_IP(x)            ((void) 0)
     2441    /* #  define NEED_IP(x)            ((void) 0) */
     2442#error "no need_ip"
    24422443#endif
    24432444#if defined(NEED_OP)
    24442445#  define HAVE_NEED_OP
    24452446#else
    2446 #  define NEED_OP(x)            ((void) 0)
     2447    /* #  define NEED_OP(x)            ((void) 0) */
     2448#error "no need_op"
    24472449#endif
    24482450
     
    25132515        if (t < 4)
    25142516            goto match_next;
    2515         assert(t > 0); NEED_OP(t); NEED_IP(t+1);
     2517        assert(t > 0); NEED_OP(t, 0); NEED_IP(t, 1);
    25162518        do *op++ = *ip++; while (--t > 0);
    25172519        goto first_literal_run;
     
    25252527        if (t == 0)
    25262528        {
    2527             NEED_IP(1);
     2529          NEED_IP(1, 0);
    25282530            while (*ip == 0)
    25292531            {
    25302532                t += 255;
    25312533                ip++;
    2532                 NEED_IP(1);
     2534                NEED_IP(1, 0);
    25332535            }
    25342536            t += 15 + *ip++;
    25352537        }
    2536         assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
     2538        assert(t > 0); NEED_OP(t,3); NEED_IP(t,4);
    25372539#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
    25382540#if !defined(LZO_UNALIGNED_OK_4)
     
    25912593        m_pos -= *ip++ << 2;
    25922594#endif
    2593         TEST_LOOKBEHIND(m_pos,out); NEED_OP(3);
     2595        TEST_LOOKBEHIND(m_pos,out); NEED_OP(3,0);
    25942596        *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
    25952597#endif
     
    26482650                t = (t >> 5) - 1;
    26492651#endif
    2650                 TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
     2652                TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t,(3-1));
    26512653                goto copy_match;
    26522654#endif
     
    26572659                if (t == 0)
    26582660                {
    2659                     NEED_IP(1);
     2661                  NEED_IP(1,0);
    26602662                    while (*ip == 0)
    26612663                    {
    26622664                        t += 255;
    26632665                        ip++;
    2664                         NEED_IP(1);
     2666                        NEED_IP(1,0);
    26652667                    }
    26662668                    t += 31 + *ip++;
     
    27012703                if (t == 0)
    27022704                {
    2703                     NEED_IP(1);
     2705                  NEED_IP(1,0);
    27042706                    while (*ip == 0)
    27052707                    {
    27062708                        t += 255;
    27072709                        ip++;
    2708                         NEED_IP(1);
     2710                        NEED_IP(1,0);
    27092711                    }
    27102712                    t += 7 + *ip++;
     
    27492751                m_off = 1 + (t >> 2) + (*ip++ << 2);
    27502752#endif
    2751                 NEED_OP(2);
     2753                NEED_OP(2,0);
    27522754                t = 2; COPY_DICT(t,m_off)
    27532755#else
     
    27612763                m_pos -= *ip++ << 2;
    27622764#endif
    2763                 TEST_LOOKBEHIND(m_pos,out); NEED_OP(2);
     2765                TEST_LOOKBEHIND(m_pos,out); NEED_OP(2,0);
    27642766                *op++ = *m_pos++; *op++ = *m_pos;
    27652767#endif
     
    27692771#if defined(COPY_DICT)
    27702772
    2771             NEED_OP(t+3-1);
     2773            NEED_OP(t,(3-1));
    27722774            t += 3-1; COPY_DICT(t,m_off)
    27732775
    27742776#else
    27752777
    2776             TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
     2778            TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t,(3-1));
    27772779#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
    27782780#if !defined(LZO_UNALIGNED_OK_4)
     
    28122814
    28132815match_next:
    2814             assert(t > 0); NEED_OP(t); NEED_IP(t+1);
     2816            assert(t > 0); NEED_OP(t,0); NEED_IP(t,1);
    28152817            do *op++ = *ip++; while (--t > 0);
    28162818            t = *ip++;
Note: See TracChangeset for help on using the changeset viewer.