* [Qemu-devel] [PATCH] ide: Fix error messages from static code analysis (no real error)
@ 2012-09-03 20:13 Stefan Weil
2012-09-04 11:00 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2012-09-03 20:13 UTC (permalink / raw)
To: Kevin Wolf; +Cc: Stefan Weil, qemu-devel
Report from smatch:
hw/ide/core.c:1472 ide_exec_cmd(423) error: buffer overflow 'smart_attributes' 8 <= 29
hw/ide/core.c:1474 ide_exec_cmd(425) error: buffer overflow 'smart_attributes' 8 <= 29
hw/ide/core.c:1475 ide_exec_cmd(426) error: buffer overflow 'smart_attributes' 8 <= 29
...
The upper limit of 30 was never reached because both for loops terminated
when 'smart_attributes' reached end of list, so there was no real buffer
overflow.
Nevertheless, changing the code not only fixes the error report, but also
reduces the size of smart_attributes and simplifies the for loops.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
Note: scripts/checkpatch.pl reports warnings and errors caused by tabs and
wrong indentation. I did not fix that because the whole file is full of tabs.
- sw
hw/ide/core.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 978dd5e..dc04621 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -53,8 +53,6 @@ static const int smart_attributes[][12] = {
{ 0x0c, 0x03, 0x00, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
/* airflow-temperature-celsius */
{ 190, 0x03, 0x00, 0x45, 0x45, 0x1f, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x32},
- /* end of list */
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
};
static int ide_handle_rw_error(IDEState *s, int error, int op);
@@ -1468,9 +1466,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
case SMART_READ_THRESH:
memset(s->io_buffer, 0, 0x200);
s->io_buffer[0] = 0x01; /* smart struct version */
- for (n=0; n<30; n++) {
- if (smart_attributes[n][0] == 0)
- break;
+ for (n = 0; n < ARRAY_SIZE(smart_attributes); n++) {
s->io_buffer[2+0+(n*12)] = smart_attributes[n][0];
s->io_buffer[2+1+(n*12)] = smart_attributes[n][11];
}
@@ -1484,10 +1480,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
case SMART_READ_DATA:
memset(s->io_buffer, 0, 0x200);
s->io_buffer[0] = 0x01; /* smart struct version */
- for (n=0; n<30; n++) {
- if (smart_attributes[n][0] == 0) {
- break;
- }
+ for (n = 0; n < ARRAY_SIZE(smart_attributes); n++) {
int i;
for(i = 0; i < 11; i++) {
s->io_buffer[2+i+(n*12)] = smart_attributes[n][i];
--
1.7.10
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] ide: Fix error messages from static code analysis (no real error)
2012-09-03 20:13 [Qemu-devel] [PATCH] ide: Fix error messages from static code analysis (no real error) Stefan Weil
@ 2012-09-04 11:00 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2012-09-04 11:00 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
Am 03.09.2012 22:13, schrieb Stefan Weil:
> Report from smatch:
> hw/ide/core.c:1472 ide_exec_cmd(423) error: buffer overflow 'smart_attributes' 8 <= 29
> hw/ide/core.c:1474 ide_exec_cmd(425) error: buffer overflow 'smart_attributes' 8 <= 29
> hw/ide/core.c:1475 ide_exec_cmd(426) error: buffer overflow 'smart_attributes' 8 <= 29
> ...
>
> The upper limit of 30 was never reached because both for loops terminated
> when 'smart_attributes' reached end of list, so there was no real buffer
> overflow.
>
> Nevertheless, changing the code not only fixes the error report, but also
> reduces the size of smart_attributes and simplifies the for loops.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> Note: scripts/checkpatch.pl reports warnings and errors caused by tabs and
> wrong indentation. I did not fix that because the whole file is full of tabs.
>
> - sw
Thanks, applied to block-next.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-04 11:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-03 20:13 [Qemu-devel] [PATCH] ide: Fix error messages from static code analysis (no real error) Stefan Weil
2012-09-04 11:00 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).