index_overflow: fix false positives when we're memcpy()ing zero bytes
commitb68b02c0f7433c0d37a214903bdf1787d415dc24
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 30 Jul 2021 12:32:46 +0000 (30 15:32 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Fri, 30 Jul 2021 12:32:46 +0000 (30 15:32 +0300)
treeb8ca1b9f3d7d97a6c3feb7d66a952efe8b0820fd
parent3ed18385db862d0969ee0984d53d5eb024ad98c6
index_overflow: fix false positives when we're memcpy()ing zero bytes

It's pretty common to do:

        memcpy(byte_array[idx], src, sizeof(byte_array) - idx);

In this code "idx" can be equal to sizeof(byte_array) but it's not a bug
because in that case we're going to copy zero bytes.  Smatch was printing
a warning for this code, and it should not.

My fix is to say that if the array is part of a memcpy and the rl_max() is
the size of the array then don't warn.

I could have written a more fine grained fix for this, which checked for
if the rl_max() == size then is the memcpy() size definitely zero?  But
that seemed more complicated than it was worth.  There is a separate
memcpy() overflow check where that warning belongs.

Reported-by: Fabio Aiuto <fabioaiuto83@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
check_index_overflow.c