Off by one in drivers/usb/input/yealink.c
Subsystems (3)
PATCH 1/1 Off by one in drivers/usb/input/yealink.c
hi,
another off by one spotted by coverity (id #485),
we loop exactly one time too often
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1 -1
@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );/* nothing todo, wait a bit and poll for a KEYPRESS */ yld->stat_ix =0 ;
Quoted 10 lines · On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
hi,
another off by one spotted by coverity (id #485),
we loop exactly one time too oftenSigned-off-by Eric Sesterhenn <[email protected]>
drivers/usb/input/yealink.c static int yealink_do_idle_tasks(struct · line 356
Quoted 8 lines
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1
-1@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );/* nothing todo, wait a bit and poll for a KEYPRESS */ yld->stat_ix =0 ;
FWIW, on this one and the previous floppy.c patch, I would rather see the comparison be <= instead of using -1.
---
~Randy
Quoted 18 lines · * Randy.Dunlap ([email protected]) wrote:
Quoted 16 lines · On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
hi,
another off by one spotted by coverity (id #485),
we loop exactly one time too oftenSigned-off-by Eric Sesterhenn <[email protected]>drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1
-1@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );
Quoted 5 lines
drivers/usb/input/yealink.c static int yealink_do_idle_tasks(struct · line 356
Quoted 2 lines
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +0
-0/* nothing todo, wait a bit and poll for a KEYPRESS */ yld->stat_ix =0 ;FWIW, on this one and the previous
floppy.cpatch, I would rather see the comparison be <= instead of using -1.
maybe it is too late, but wouldnt the <= make the loop run even more iterations, like (++ix < sizeof() + 1)
greetings, Eric
Quoted 15 lines · On Wed, 28 Jun 2006 01:04:16 +0200 Eric Sesterhenn / Snakebyte wrote:
Quoted 14 lines · * Randy.Dunlap ([email protected]) wrote:
Quoted 12 lines · On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
another off by one spotted by coverity (id #485),
we loop exactly one time too oftendrivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1
-1@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );
Quoted 8 lines
Quoted 5 lines
drivers/usb/input/yealink.c static int yealink_do_idle_tasks(struct · line 356
Quoted 2 lines
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +0
-0/* nothing todo, wait a bit and poll for a KEYPRESS */ yld->stat_ix =0 ;FWIW, on this one and the previous
floppy.cpatch, I would rather see the comparison be <= instead of using -1.maybe it is too late, but wouldnt the <= make the loop run even more iterations, like (++ix <
sizeof()+ 1)
:) Yep.
so for the floppy.c patch, I still prefer to see:
+ if (drive < 0 || drive >= N_DRIVE) {
instead of
+ if (drive < 0 || drive > N_DRIVE-1) {
Does that make sense?
---
~Randy
Quoted 9 lines
:) Yep.
so for the
floppy.cpatch, I still prefer to see:(quoted diff) +1
-0+ if (drive < 0 || drive >= N_DRIVE) {instead of
(quoted diff) +1
-0+ if (drive < 0 || drive > N_DRIVE-1) {Does that make sense?
looks better :)
---
another bug spotted by coverity (id #481). In the case that drive == N_DRIVE we acess past the drive_params array which is defined as drive_params[N_DRIVE]. By using the UDP define in the else case because UDP is &drive_params[drive]
drivers/block/floppy.c renamed from drivers/block/floppy.c.orig +1 -1
@@ -684,7 +684,7 @@ static void __reschedule_timeout(int driif (drive == current_reqD) drive = current_drive;del_timer (&fd_timeout); -if (drive <0 || drive >N_DRIVE ) { +if (drive <0 || drive >=N_DRIVE ) { fd_timeout.expires = jiffies +20UL *HZ ; drive =0 ; }else
Sorry for the late response guys, but I was on holliday.
No no no, please dont use this.
Quoted 6 lines · Randy.Dunlap
Quoted 5 lines · On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
another off by one spotted by coverity (id #485),
we loop exactly one time too oftenSigned-off-by Eric Sesterhenn <[email protected]>
Quoted 8 lines
drivers/usb/input/yealink.c static int yealink_do_idle_tasks(struct · line 353
Quoted 8 lines
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1
-1@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );
Apart from introducing a new bug in the code, the construct is ugly.
I would rather see then the more readable:
ix++;
} while (ix < sizeof(yld->master));- Henk
Quoted 23 lines · * Dmitry Torokhov ([email protected]) wrote:
Quoted 22 lines · Henk Vergonet
Quoted 7 lines · Randy.Dunlap
Quoted 6 lines · On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
another off by one spotted by coverity (id #485),
we loop exactly one time too oftenSigned-off-by Eric Sesterhenn <[email protected]>--- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28
00:29:46.000000000 +0200
Quoted 1 line
Quoted 1 line
+++
linux-2.6.17-git11/drivers/usb/input/yealink.c2006-06-2800:30:04.000000000 +0200
Quoted 6 lines
drivers/usb/input/yealink.c static int yealink_do_idle_tasks(struct · line 353
Quoted 6 lines
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1
-1@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );Apart from introducing a new bug in the code, the construct is ugly.
I would rather see then the more readable:
Quoted 7 lines
Quoted 3 lines
ix++;} while (ix <
sizeof(yld->master));The new code is exactly the same as the old one; however I do not see the problem with the old code. Could it be that Coverity got confused by prefix vs. postfix increment?
I looked at this code several times too, and tried to reproduce the bug with the following little program:
#include <string.h>
int main(int argc, char **argv) {
char foo[] = "abcdef";
int i = 0;
foo[strlen(foo)] = 'X';
do {
putchar(foo[i]);
} while (++i < sizeof(foo));
}Which clearly shows that the terminating '\0' gets printed too, replaced by the X for better visibility, so the code runs past the array, or did I fail to replicate the original code somewhere?
Eric
Quoted 46 lines · Eric Sesterhenn / Snakebyte
Quoted 23 lines · * Dmitry Torokhov ([email protected]) wrote:
Quoted 22 lines · Henk Vergonet
Quoted 7 lines · Randy.Dunlap
Quoted 6 lines · On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
another off by one spotted by coverity (id #485),
we loop exactly one time too oftenSigned-off-by Eric Sesterhenn <[email protected]>--- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28
00:29:46.000000000 +0200
Quoted 1 line
Quoted 1 line
+++
linux-2.6.17-git11/drivers/usb/input/yealink.c2006-06-2800:30:04.000000000 +0200
Quoted 6 lines
drivers/usb/input/yealink.c static int yealink_do_idle_tasks(struct · line 353
Quoted 6 lines
drivers/usb/input/yealink.c renamed from drivers/usb/input/yealink.c.orig +1
-1@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct val = yld->master.b[ix];if (val != yld->copy.b[ix]) goto send_update; - }while (++ix <sizeof (yld->master)); + }while (++ix <sizeof (yld->master)-1 );Apart from introducing a new bug in the code, the construct is ugly.
I would rather see then the more readable:
Quoted 7 lines
Quoted 3 lines
ix++;} while (ix <
sizeof(yld->master));The new code is exactly the same as the old one; however I do not see the problem with the old code. Could it be that Coverity got confused by prefix vs. postfix increment?
I looked at this code several times too, and tried to reproduce the bug with the following little program:
#include <
string.h>int main(int argc, char **argv) { char foo[] = "abcdef"; int i = 0; foo[strlen(foo)] = 'X'; do { putchar(foo[i]); } while (++i < sizeof(foo)); }
Quoted 5 lines
Which clearly shows that the terminating '\0' gets printed too, replaced by the X for better visibility, so the code runs past the array, or did I fail to replicate the original code somewhere?
What do you mean "the code runs past the array"? The size of array is 7 (compiler allocates the space for terminating '\0') and the array is printed in its entirety.
Signature · 1 line
Dmitry
Quoted 21 lines · * Dmitry Torokhov ([email protected]) wrote:
Quoted 14 lines · Eric Sesterhenn / Snakebyte
I looked at this code several times too, and tried to reproduce the bug with the following little program:
#include <
string.h>int main(int argc, char **argv) { char foo[] = "abcdef"; int i = 0; foo[strlen(foo)] = 'X'; do { putchar(foo[i]); } while (++i < sizeof(foo)); }Quoted 5 lines
Which clearly shows that the terminating '\0' gets printed too, replaced by the X for better visibility, so the code runs past the array, or did I fail to replicate the original code somewhere?
Quoted 3 lines
What do you mean "the code runs past the array"? The size of array is 7 (compiler allocates the space for terminating '\0') and the array is printed in its entirety.
arg, of course \0 is part of the array, sorry bothering you guys with this stuff :( Another coverity report i analyzed incorrect... :(
Eric