[Stgt-devel] [PATCH 1/2] driver: fix array bounds checking

FUJITA Tomonori fujita.tomonori
Fri May 30 19:09:58 CEST 2008


On Thu, 29 May 2008 13:51:34 -0400
Pete Wyckoff <pw at osc.edu> wrote:

> Gcc 4.3.0 noticed that the check on tgt_drivers[i] after
> the loop could exceed the static bounds of the array.  Impressive.

Yeah, pretty impressive.


> Fix that by reordering the logic.
> 
> Signed-off-by: Pete Wyckoff <pw at osc.edu>
> ---
>  usr/driver.c |   13 ++++++-------
>  1 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/usr/driver.c b/usr/driver.c
> index c555398..d886e86 100644
> --- a/usr/driver.c
> +++ b/usr/driver.c
> @@ -49,12 +49,11 @@ int register_driver(struct tgt_driver *drv)
>  {
>  	int i;
>  
> -	for (i = 0; i < ARRAY_SIZE(tgt_drivers) && tgt_drivers[i]; i++)
> -		;
> +	for (i = 0; i < ARRAY_SIZE(tgt_drivers); i++)
> +		if (tgt_drivers[i] == NULL) {

I modified in the following way:

if (!tgt_drivers[i]) {


Applied, thanks.



More information about the stgt mailing list