crypto: fix above array bounds warning in nuttx crypto
crypto.c:440:38: warning: array subscript 24 is above array bounds of 'int[24]' [-Warray-bounds]
440 | crypto_drivers[driverid].cc_alg[alg] == 0)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from crypto.c:37:
nuttx/include/crypto/cryptodev.h:269:7: note: while referencing 'cc_alg'
269 | int cc_alg[CRYPTO_ALGORITHM_MAX + 1];
following commit cbf8475b93
(1)alg need to blong to [1, CRYPTO_ALGORITHM_MAX + 1] in sanity checks
(2)clear alg algorithm when alg blongs to [1, CRYPTO_ALGORITHM_MAX + 1)
(3)clear all algorithms when alg equals to CRYPTO_ALGORITHM_MAX + 1
Signed-off-by: makejian <makejian@xiaomi.com>
This commit is contained in:
parent
5e0e027880
commit
b6c2362c6a
@ -435,9 +435,7 @@ int crypto_unregister(uint32_t driverid, int alg)
|
||||
/* Sanity checks. */
|
||||
|
||||
if (driverid >= crypto_drivers_num || crypto_drivers == NULL ||
|
||||
((alg <= 0 || alg > CRYPTO_ALGORITHM_MAX) &&
|
||||
alg != CRYPTO_ALGORITHM_MAX + 1) ||
|
||||
crypto_drivers[driverid].cc_alg[alg] == 0)
|
||||
alg <= 0 || alg > (CRYPTO_ALGORITHM_MAX + 1))
|
||||
{
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -EINVAL;
|
||||
@ -445,6 +443,12 @@ int crypto_unregister(uint32_t driverid, int alg)
|
||||
|
||||
if (alg != CRYPTO_ALGORITHM_MAX + 1)
|
||||
{
|
||||
if (crypto_drivers[driverid].cc_alg[alg] == 0)
|
||||
{
|
||||
nxmutex_unlock(&g_crypto_lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
crypto_drivers[driverid].cc_alg[alg] = 0;
|
||||
|
||||
/* Was this the last algorithm ? */
|
||||
|
Loading…
Reference in New Issue
Block a user