[igt-dev] [PATCH i-g-t] lib/igt_vec: assertion fortification

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Feb 7 03:27:25 UTC 2020


Ensure no one will pass negative index on igt_vec because it could
lead to memory corruptions and weird program behavior.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_vec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/igt_vec.c b/lib/igt_vec.c
index 591e56fa..c6ba164b 100644
--- a/lib/igt_vec.c
+++ b/lib/igt_vec.c
@@ -41,7 +41,7 @@ void igt_vec_fini(struct igt_vec *vec)
 
 void *igt_vec_elem(const struct igt_vec *vec, int idx)
 {
-	igt_assert(idx < vec->len);
+	igt_assert(idx >= 0 && idx < vec->len);
 
 	return vec->elems + idx * vec->elem_size;
 }
@@ -79,7 +79,7 @@ int igt_vec_index(const struct igt_vec *vec, void *elem)
 
 void igt_vec_remove(struct igt_vec *vec, int idx)
 {
-	igt_assert(idx < vec->len);
+	igt_assert(idx >= 0 && idx < vec->len);
 
 	memmove(igt_vec_elem(vec, idx),
 		igt_vec_elem(vec, idx + 1),
-- 
2.23.0



More information about the igt-dev mailing list