diff mbox series

target/xtensa: Correct assert condition in handle_interrupt()

Message ID 20240731172246.3682311-1-peter.maydell@linaro.org (mailing list archive)
State New, archived
Headers show
Series target/xtensa: Correct assert condition in handle_interrupt() | expand

Commit Message

Peter Maydell July 31, 2024, 5:22 p.m. UTC
In commit ad18376b90c8101 we added an assert that the level value was
in-bounds for the array we're about to index into.  However, the
assert condition is wrong -- env->config->interrupt_vector is an
array of uint32_t, so we should bounds check the index against
ARRAY_SIZE(...), not against sizeof().

Resolves: Coverity CID 1507131
Fixes: ad18376b90c8101 ("target/xtensa: Assert that interrupt level is within bounds")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Spotted because Coverity (correctly) thought the issue was still
outstanding.
---
 target/xtensa/exc_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Max Filippov July 31, 2024, 5:41 p.m. UTC | #1
On Wed, Jul 31, 2024 at 10:22 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> In commit ad18376b90c8101 we added an assert that the level value was
> in-bounds for the array we're about to index into.  However, the
> assert condition is wrong -- env->config->interrupt_vector is an
> array of uint32_t, so we should bounds check the index against
> ARRAY_SIZE(...), not against sizeof().
>
> Resolves: Coverity CID 1507131
> Fixes: ad18376b90c8101 ("target/xtensa: Assert that interrupt level is within bounds")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Spotted because Coverity (correctly) thought the issue was still
> outstanding.
> ---
>  target/xtensa/exc_helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Philippe Mathieu-Daudé July 31, 2024, 9:10 p.m. UTC | #2
On 31/7/24 19:22, Peter Maydell wrote:
> In commit ad18376b90c8101 we added an assert that the level value was
> in-bounds for the array we're about to index into.  However, the
> assert condition is wrong -- env->config->interrupt_vector is an
> array of uint32_t, so we should bounds check the index against
> ARRAY_SIZE(...), not against sizeof().
> 
> Resolves: Coverity CID 1507131
> Fixes: ad18376b90c8101 ("target/xtensa: Assert that interrupt level is within bounds")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Spotted because Coverity (correctly) thought the issue was still
> outstanding.
> ---
>   target/xtensa/exc_helper.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/target/xtensa/exc_helper.c b/target/xtensa/exc_helper.c
index 0514c2c1f32..ca629f071d1 100644
--- a/target/xtensa/exc_helper.c
+++ b/target/xtensa/exc_helper.c
@@ -171,7 +171,7 @@  static void handle_interrupt(CPUXtensaState *env)
 
         if (level > 1) {
             /* env->config->nlevel check should have ensured this */
-            assert(level < sizeof(env->config->interrupt_vector));
+            assert(level < ARRAY_SIZE(env->config->interrupt_vector));
 
             env->sregs[EPC1 + level - 1] = env->pc;
             env->sregs[EPS2 + level - 2] = env->sregs[PS];