mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 13:52:22 +08:00
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 https://github.com/openbsd/src/commit/cbf8475b9318827d4174f247f210e07ba24f7ac2
(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:
+7
-3
@@ -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 ? */
|
||||
|
||||
Reference in New Issue
Block a user