[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/7] hw/misc/pca9554: Correct error check bounds in get/set pin f
From: |
Peter Maydell |
Subject: |
[PATCH 4/7] hw/misc/pca9554: Correct error check bounds in get/set pin functions |
Date: |
Tue, 12 Mar 2024 18:38:07 +0000 |
In pca9554_get_pin() and pca9554_set_pin(), we try to detect an
incorrect pin value, but we get the condition wrong, using ">"
when ">=" was intended.
This has no actual effect, because in pca9554_initfn() we
use the correct test when creating the properties and so
we'll never be called with an out of range value. However,
Coverity complains about the mismatch between the check and
the later use of the pin value in a shift operation.
Use the correct condition.
Resolves: Coverity CID 1534917
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/misc/pca9554.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/misc/pca9554.c b/hw/misc/pca9554.c
index 778b32e4430..5e31696797d 100644
--- a/hw/misc/pca9554.c
+++ b/hw/misc/pca9554.c
@@ -160,7 +160,7 @@ static void pca9554_get_pin(Object *obj, Visitor *v, const
char *name,
error_setg(errp, "%s: error reading %s", __func__, name);
return;
}
- if (pin < 0 || pin > PCA9554_PIN_COUNT) {
+ if (pin < 0 || pin >= PCA9554_PIN_COUNT) {
error_setg(errp, "%s invalid pin %s", __func__, name);
return;
}
@@ -187,7 +187,7 @@ static void pca9554_set_pin(Object *obj, Visitor *v, const
char *name,
error_setg(errp, "%s: error reading %s", __func__, name);
return;
}
- if (pin < 0 || pin > PCA9554_PIN_COUNT) {
+ if (pin < 0 || pin >= PCA9554_PIN_COUNT) {
error_setg(errp, "%s invalid pin %s", __func__, name);
return;
}
--
2.34.1
- [PATCH 0/7] various: 7 minor Coverity fixes, Peter Maydell, 2024/03/12
- [PATCH 4/7] hw/misc/pca9554: Correct error check bounds in get/set pin functions,
Peter Maydell <=
- [PATCH 5/7] hw/nvram/mac_nvram: Report failure to write data, Peter Maydell, 2024/03/12
- [PATCH 6/7] tests/unit/test-throttle: Avoid unintended integer division, Peter Maydell, 2024/03/12
- [PATCH 2/7] tests/unit/socket-helpers: Don't close(-1), Peter Maydell, 2024/03/12
- [PATCH 3/7] net/af-xdp.c: Don't leak sock_fds array in net_init_af_xdp(), Peter Maydell, 2024/03/12
- [PATCH 7/7] tests/qtest/libqtest.c: Check for g_setenv() failure, Peter Maydell, 2024/03/12
- [PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line, Peter Maydell, 2024/03/12