2014-07-18 17:40:35

by Andrey Utkin

[permalink] [raw]
Subject: [PATCH] kernel/debug/kdb/kdb_bp.c: fix argument range check

Dropped negativity check; enhanced upper limit check as proposed by
Walter Harms <[email protected]>

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80591
Reported-by: David Binderman <[email protected]>
Signed-off-by: Andrey Utkin <[email protected]>
---
kernel/debug/kdb/kdb_bp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c
index 70a5046..371150f 100644
--- a/kernel/debug/kdb/kdb_bp.c
+++ b/kernel/debug/kdb/kdb_bp.c
@@ -39,7 +39,7 @@ static char *kdb_rwtypes[] = {

static char *kdb_bptype(kdb_bp_t *bp)
{
- if (bp->bp_type < 0 || bp->bp_type > 4)
+ if (bp->bp_type >= ARRAY_SIZE(kdb_rwtypes))
return "";

return kdb_rwtypes[bp->bp_type];
--
1.8.5.5


2014-07-22 07:53:38

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] kernel/debug/kdb/kdb_bp.c: fix argument range check

On Fri, Jul 18, 2014 at 08:40:24PM +0300, Andrey Utkin wrote:
> Dropped negativity check; enhanced upper limit check as proposed by
> Walter Harms <[email protected]>
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80591
> Reported-by: David Binderman <[email protected]>
> Signed-off-by: Andrey Utkin <[email protected]>
> ---
> kernel/debug/kdb/kdb_bp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c
> index 70a5046..371150f 100644
> --- a/kernel/debug/kdb/kdb_bp.c
> +++ b/kernel/debug/kdb/kdb_bp.c
> @@ -39,7 +39,7 @@ static char *kdb_rwtypes[] = {
>
> static char *kdb_bptype(kdb_bp_t *bp)
> {
> - if (bp->bp_type < 0 || bp->bp_type > 4)
> + if (bp->bp_type >= ARRAY_SIZE(kdb_rwtypes))
> return "";

I like this version of the patch because it silences the static checker
warning like the first one does but it also makes the code more
readable.

regards,
dan carpenter