Project

General

Profile

nmalloc.c.diff

diff against /lib/libc/stdlib/nmalloc.c - ddegroot, 12/30/2017 04:21 PM

View differences:

lib/libc/stdlib/nmalloc.c
753 753
       return(0);
754 754
}
755 755

  
756
#define MUL_NO_OVERFLOW        (1UL << (sizeof(size_t) * 4))
757

  
756 758
/*
757 759
 * malloc() - call internal slab allocator
758 760
 */
......
761 763
{
762 764
       void *ptr;
763 765

  
766
       if ((size >= MUL_NO_OVERFLOW ) || (SIZE_MAX < size)) {
767
               errno = ENOMEM;
768
               return(NULL);
769
       }
770

  
764 771
       ptr = _slaballoc(size, 0);
765 772
       if (ptr == NULL)
766 773
               errno = ENOMEM;
......
769 776
       return(ptr);
770 777
}
771 778

  
772
#define MUL_NO_OVERFLOW        (1UL << (sizeof(size_t) * 4))
773

  
774 779
/*
775 780
 * calloc() - call internal slab allocator
776 781
 */
......
982 987
               bigalloc_t big;
983 988
               bigalloc_t *bigp;
984 989

  
990
               if ((size >= MUL_NO_OVERFLOW ) || (SIZE_MAX < size) ) {
991
                       return(NULL);
992
               }
985 993
               /*
986 994
                * Page-align and cache-color in case of virtually indexed
987 995
                * physically tagged L1 caches (aka SandyBridge).  No sweat
......
989 997
                *
990 998
                * (don't count as excess).
991 999
                */
992
               size = (size + PAGE_MASK) & ~(size_t)PAGE_MASK;
1000
               size = (size + PAGE_MASK) & ~(size_t)PAGE_MASK;         /* Note: Changing size, without checking overflow.
1001
                                                                          also might be better to use a different variable instead of the original request size */
993 1002

  
994 1003
               /*
995 1004
                * If we have overflown above when rounding to the page