[igt-dev] [PATCH i-g-t] lib/igt_vec: assertion fortification
Ville Syrjälä
ville.syrjala at linux.intel.com
Fri Feb 7 13:07:19 UTC 2020
On Fri, Feb 07, 2020 at 04:27:25AM +0100, Zbigniew Kempczyński wrote:
> 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>
Reviewed-by: 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
--
Ville Syrjälä
Intel
More information about the igt-dev
mailing list