qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] target/i386: Use assert() to sanity-check b1 in SSE decod


From: Richard Henderson
Subject: Re: [PATCH v2] target/i386: Use assert() to sanity-check b1 in SSE decode
Date: Fri, 3 Sep 2021 15:10:40 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

On 9/1/21 4:10 PM, Peter Maydell wrote:
In the SSE decode function gen_sse(), we combine a byte
'b' and a value 'b1' which can be [0..3], and switch on them:
    b |= (b1 << 8);
    switch (b) {
    ...
    default:
    unknown_op:
        gen_unknown_opcode(env, s);
        return;
    }

In three cases inside this switch, we were then also checking for
  "if (b1 >= 2) { goto unknown_op; }".
However, this can never happen, because the 'case' values in each place
are 0x0nn or 0x1nn and the switch will have directed the b1 == (2, 3)
cases to the default already.

This check was added in commit c045af25a52e9 in 2010; the added code
was unnecessary then as well, and was apparently intended only to
ensure that we never accidentally ended up indexing off the end
of an sse_op_table with only 2 entries as a result of future bugs
in the decode logic.

Change the checks to assert() instead, and make sure they're always
immediately before the array access they are protecting.

Fixes: Coverity CID 1460207
Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
---
v1->v2: use assert() rather than just deleting the if()s

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]