VirtualBox

Changeset 58734 in vbox for trunk/src/libs/xpcom18a4/nsprpub


Ignore:
Timestamp:
Nov 18, 2015 10:24:35 AM (9 years ago)
Author:
vboxsync
Message:

libs/xpcom: fix (just in case) for sloppy code

Location:
trunk/src/libs/xpcom18a4/nsprpub/lib/ds
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plarena.c

    r1 r58734  
    116116    pool->mask = PR_BITMASK(PR_CeilingLog2(align));
    117117    pool->first.next = NULL;
     118    /* Set all three addresses in pool->first to the same dummy value.
     119     * These addresses are only compared with each other, but never
     120     * dereferenced. */
    118121    pool->first.base = pool->first.avail = pool->first.limit =
    119122        (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
     
    159162    PLArena *a;   
    160163    char *rp;     /* returned pointer */
     164    PRUint32 nbOld;
    161165
    162166    PR_ASSERT((nb & pool->mask) == 0);
    163167   
     168    nbOld = nb;
    164169    nb = (PRUword)PL_ARENA_ALIGN(pool, nb); /* force alignment */
     170    if (nb < nbOld)
     171        return NULL;
    165172
    166173    /* attempt to allocate from arenas at pool->current */
     
    218225            rp = (char *)a->avail;
    219226            a->avail += nb;
     227            PR_ASSERT(a->avail <= a->limit);
    220228            /* the newly allocated arena is linked after pool->current
    221229            *  and becomes pool->current */
     
    240248    void *newp;
    241249
     250    if (PR_UINT32_MAX - size < incr)
     251        return NULL;
    242252    PL_ARENA_ALLOCATE(newp, pool, size + incr);
    243253    if (newp)
  • trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plarena.h

    r1 r58734  
    109109    PR_BEGIN_MACRO \
    110110        PLArena *_a = (pool)->current; \
    111         PRUint32 _nb = PL_ARENA_ALIGN(pool, nb); \
     111        PRUint32 _nb = PL_ARENA_ALIGN(pool, (PRUint32)nb); \
    112112        PRUword _p = _a->avail; \
    113         PRUword _q = _p + _nb; \
    114         if (_q > _a->limit) \
     113        if (_nb < (PRUint32)nb) { \
     114            _p = 0; \
     115        } else if (_nb > (_a->limit - _a->avail)) { \
    115116            _p = (PRUword)PL_ArenaAllocate(pool, _nb); \
    116         else \
    117             _a->avail = _q; \
     117        } else { \
     118            _a->avail += _nb; \
     119        } \
    118120        p = (void *)_p; \
    119         PL_ArenaCountAllocation(pool, nb); \
     121        if (p) { \
     122            PL_ArenaCountAllocation(pool, nb); \
     123        } \
    120124    PR_END_MACRO
    121125
     
    123127    PR_BEGIN_MACRO \
    124128        PLArena *_a = (pool)->current; \
    125         PRUint32 _incr = PL_ARENA_ALIGN(pool, incr); \
    126         PRUword _p = _a->avail; \
    127         PRUword _q = _p + _incr; \
    128         if (_p == (PRUword)(p) + PL_ARENA_ALIGN(pool, size) && \
    129             _q <= _a->limit) { \
    130             _a->avail = _q; \
    131             PL_ArenaCountInplaceGrowth(pool, size, incr); \
     129        PRUint32 _incr = PL_ARENA_ALIGN(pool, (PRUint32)incr); \
     130        if (_incr < (PRUint32)incr) { \
     131            p = NULL; \
     132        } else if (_a->avail == (PRUword)(p) + PL_ARENA_ALIGN(pool, size) && \
     133            _incr <= (_a->limit - _a->avail)) { \
     134            _a->avail = _incr; \
     135            PL_ArenaCountInplaceGrowth(pool, size, (RTUint32)incr); \
    132136        } else { \
    133             p = PL_ArenaGrow(pool, p, size, incr); \
    134         } \
    135         PL_ArenaCountGrowth(pool, size, incr); \
     137            p = PL_ArenaGrow(pool, p, size, (PRUint32)incr); \
     138        } \
     139        if (p) { \
     140            PL_ArenaCountGrowth(pool, size, (PRUint32)incr); \
     141        } \
    136142    PR_END_MACRO
    137143
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette