sr: fix possible null-pointer dereference
[vpp.git] / src / vppinfra / vec.h
index 6f0e7e9..021b229 100644 (file)
@@ -138,6 +138,7 @@ _vec_resize_inline (void *v,
       /* Typically we'll not need to resize. */
       if (new_data_bytes <= clib_mem_size (p))
        {
+         CLIB_MEM_UNPOISON (v, data_bytes);
          vh->len += length_increment;
          return v;
        }
@@ -480,8 +481,6 @@ do {                                                                \
     @param V (possibly NULL) pointer to a vector.
     @param I vector index which will be valid upon return
     @param INIT initial value (can be a complex expression!)
-    @param H header size in bytes (may be zero)
-    @param A alignment (may be zero)
     @return V (value-result macro parameter)
 */
 
@@ -494,7 +493,6 @@ do {                                                                \
     @param V (possibly NULL) pointer to a vector.
     @param I vector index which will be valid upon return
     @param INIT initial value (can be a complex expression!)
-    @param H header size in bytes (may be zero)
     @param A alignment (may be zero)
     @return V (value-result macro parameter)
 */
@@ -528,7 +526,6 @@ do {                                                                        \
 
     @param V pointer to a vector
     @param E element to add
-    @param H header size in bytes (may be zero)
     @param A alignment (may be zero)
     @return V (value-result macro parameter)
 */
@@ -798,6 +795,7 @@ do {                                                                \
   if (_v(n) > 0)                                               \
     clib_memset ((V) + _v(l) - _v(n), 0, _v(n) * sizeof ((V)[0]));     \
   _vec_len (V) -= _v(n);                                       \
+  CLIB_MEM_POISON(vec_end(V), _v(n) * sizeof ((V)[0]));         \
 } while (0)
 
 /** \brief Delete the element at index I
@@ -812,6 +810,7 @@ do {                                                \
   if (_vec_del_i < _vec_del_l)                 \
     (v)[_vec_del_i] = (v)[_vec_del_l];         \
   _vec_len (v) = _vec_del_l;                   \
+  CLIB_MEM_POISON(vec_end(v), sizeof ((v)[0])); \
 } while (0)
 
 /** \brief Append v2 after v1. Result in v1.
@@ -937,8 +936,8 @@ do {                                                \
 
 /** \brief Search a vector for the index of the entry that matches.
 
-    @param v1 Pointer to a vector
-    @param v2 Entry to match
+    @param v Pointer to a vector
+    @param E Entry to match
     @return index of match or ~0
 */
 #define vec_search(v,E)                                        \
@@ -957,8 +956,8 @@ do {                                                \
 
 /** \brief Search a vector for the index of the entry that matches.
 
-    @param v1 Pointer to a vector
-    @param v2 Pointer to entry to match
+    @param v Pointer to a vector
+    @param E Pointer to entry to match
     @param fn Comparison function !0 => match
     @return index of match or ~0
 */