@@ -223,6 +223,10 @@ bool GetTlvUInt32(void *data, uint32_t size, uint32_t *offset,
223223 uint16_t tlvtype = GetTlvType (tlvstart);
224224 uint32_t tlvsize = GetTlvSize (tlvstart);
225225
226+ /* check that there is size - SAFE CHECK */
227+ if (tlvsize > size || *offset > size - tlvsize)
228+ return false ;
229+
226230 /* check that there is size */
227231 uint32_t tlvend = *offset + tlvsize;
228232 if (size < tlvend)
@@ -315,6 +319,10 @@ bool GetTlvUInt16(void *data, uint32_t size, uint32_t *offset,
315319 uint16_t tlvtype = GetTlvType (tlvstart);
316320 uint32_t tlvsize = GetTlvSize (tlvstart);
317321
322+ /* check that there is size - SAFE CHECK */
323+ if (tlvsize > size || *offset > size - tlvsize)
324+ return false ;
325+
318326 /* check that there is size */
319327 uint32_t tlvend = *offset + tlvsize;
320328 if (size < tlvend)
@@ -425,6 +433,10 @@ bool GetTlvUInt64(void *data, uint32_t size, uint32_t *offset,
425433 uint16_t tlvtype = GetTlvType (tlvstart);
426434 uint32_t tlvsize = GetTlvSize (tlvstart);
427435
436+ /* check that there is size - SAFE CHECK */
437+ if (tlvsize > size || *offset > size - tlvsize)
438+ return false ;
439+
428440 /* check that there is size */
429441 uint32_t tlvend = *offset + tlvsize;
430442 if (size < tlvend)
@@ -567,17 +579,17 @@ bool GetTlvString(const void *data, uint32_t size, uint32_t *offset,
567579 uint32_t tlvsize = GetTlvSize (tlvstart);
568580
569581 /* check that there is size */
570- uint32_t tlvend = *offset + tlvsize;
571- if (size < tlvend)
582+ if (tlvsize > size || *offset > size - tlvsize)
572583 {
573584#ifdef TLV_BASE_DEBUG
574585 std::cerr << " GetTlvString() FAILED - not enough space" << std::endl;
575586 std::cerr << " GetTlvString() size: " << size << std::endl;
576587 std::cerr << " GetTlvString() tlvsize: " << tlvsize << std::endl;
577- std::cerr << " GetTlvString() tlvend : " << tlvend << std::endl;
588+ std::cerr << " GetTlvString() offset : " << *offset << std::endl;
578589#endif
579590 return false ;
580591 }
592+ uint32_t tlvend = *offset + tlvsize;
581593
582594 if (type != tlvtype)
583595 {
@@ -863,6 +875,10 @@ bool GetTlvIpAddrPortV4(void *data, uint32_t size, uint32_t *offset,
863875 uint16_t tlvtype = GetTlvType (tlvstart);
864876 uint32_t tlvsize = GetTlvSize (tlvstart);
865877
878+ /* check that there is size - SAFE CHECK */
879+ if (tlvsize > size || *offset > size - tlvsize)
880+ return false ;
881+
866882 /* check that there is size */
867883 uint32_t tlvend = *offset + tlvsize;
868884 if (size < tlvend)
@@ -961,6 +977,10 @@ bool GetTlvIpAddrPortV6(void *data, uint32_t size, uint32_t *offset,
961977 uint16_t tlvtype = GetTlvType (tlvstart);
962978 uint32_t tlvsize = GetTlvSize (tlvstart);
963979
980+ /* check that there is size - SAFE CHECK */
981+ if (tlvsize > size || *offset > size - tlvsize)
982+ return false ;
983+
964984 /* check that there is size */
965985 uint32_t tlvend = *offset + tlvsize;
966986 if (size < tlvend)
0 commit comments