Commit 004ce53 Add overflow check to SAFEALIGN_COPY_*_CHECK macros

1 file Authored by sbose 7 years ago , Committed by sgallagh 7 years ago ,
Add overflow check to SAFEALIGN_COPY_*_CHECK macros

    
 1 @@ -207,12 +207,14 @@
 2       SAFEALIGN_SET_VALUE(dest, value, uint16_t, pctr)
 3   
 4   #define SAFEALIGN_COPY_UINT32_CHECK(dest, src, len, pctr) do { \
 5 -     if ((*(pctr) + sizeof(uint32_t)) > (len)) return EINVAL; \
 6 +     if ((*(pctr) + sizeof(uint32_t)) > (len) || \
 7 +         SIZE_T_OVERFLOW(*(pctr), sizeof(uint32_t))) return EINVAL; \
 8       safealign_memcpy(dest, src, sizeof(uint32_t), pctr); \
 9   } while(0)
10   
11   #define SAFEALIGN_COPY_INT32_CHECK(dest, src, len, pctr) do { \
12 -     if ((*(pctr) + sizeof(int32_t)) > (len)) return EINVAL; \
13 +     if ((*(pctr) + sizeof(int32_t)) > (len) || \
14 +         SIZE_T_OVERFLOW(*(pctr), sizeof(int32_t))) return EINVAL; \
15       safealign_memcpy(dest, src, sizeof(int32_t), pctr); \
16   } while(0)
17