From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>,
"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] bfa: clean up some bounds checking
Date: Thu, 16 Jun 2016 12:20:13 +0000 [thread overview]
Message-ID: <5762997D.3020302@bfs.de> (raw)
In-Reply-To: <20160616104434.GB24067@mwanda>
Am 16.06.2016 12:44, schrieb Dan Carpenter:
> This code is supposed to search ->adapter_hwpath[] and replace the
> second colon with a NUL character. Unfortunately, the boundary checks
> that ensure we don't go beyond the end of the buffer have a couple
> problems.
>
> Imagine that the string has no colons. In that case, in the first loop,
> we read one space beyond the end of the buffer and then exit the loop.
> In the next loop, we increment once, read two characters beyond the end
> of the buffer and then exit. Then after the loop we put a NUL character
> two characters past the end of the buffer.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This is from static analysis and not tested. Caveat emptor.
>
> diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
> index d1ad020..dfb26f0 100644
> --- a/drivers/scsi/bfa/bfad_bsg.c
> +++ b/drivers/scsi/bfa/bfad_bsg.c
> @@ -106,10 +106,17 @@ bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd)
>
> /* set adapter hw path */
> strcpy(iocmd->adapter_hwpath, bfad->pci_name);
> - for (i = 0; iocmd->adapter_hwpath[i] != ':' && i < BFA_STRING_32; i++)
> - ;
> - for (; iocmd->adapter_hwpath[++i] != ':' && i < BFA_STRING_32; )
> - ;
> + i = -1;
> + while (++i < BFA_STRING_32) {
> + if (iocmd->adapter_hwpath[i] = ':')
> + break;
> + }
> + while (++i < BFA_STRING_32) {
> + if (iocmd->adapter_hwpath[i] = ':')
> + break;
> + }
> + if (i >= BFA_STRING_32)
> + i = BFA_STRING_32 - 1;
> iocmd->adapter_hwpath[i] = '\0';
> iocmd->status = BFA_STATUS_OK;
> return 0;
I do not see the use case but i assume
the idea is to have a string like aa:bb:something
and kill everyhing after the second ':' ?
/*
a few word may help here also inside the code
*/
second: maybe we can us strchr here ?
s1=strchr(iocmd->adapter_hwpath,':');
if (s1 != NULL ) s1=strchr(s1,":");
re,
wh
WARNING: multiple messages have this Message-ID (diff)
From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>,
"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] bfa: clean up some bounds checking
Date: Thu, 16 Jun 2016 14:20:13 +0200 [thread overview]
Message-ID: <5762997D.3020302@bfs.de> (raw)
In-Reply-To: <20160616104434.GB24067@mwanda>
Am 16.06.2016 12:44, schrieb Dan Carpenter:
> This code is supposed to search ->adapter_hwpath[] and replace the
> second colon with a NUL character. Unfortunately, the boundary checks
> that ensure we don't go beyond the end of the buffer have a couple
> problems.
>
> Imagine that the string has no colons. In that case, in the first loop,
> we read one space beyond the end of the buffer and then exit the loop.
> In the next loop, we increment once, read two characters beyond the end
> of the buffer and then exit. Then after the loop we put a NUL character
> two characters past the end of the buffer.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This is from static analysis and not tested. Caveat emptor.
>
> diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
> index d1ad020..dfb26f0 100644
> --- a/drivers/scsi/bfa/bfad_bsg.c
> +++ b/drivers/scsi/bfa/bfad_bsg.c
> @@ -106,10 +106,17 @@ bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd)
>
> /* set adapter hw path */
> strcpy(iocmd->adapter_hwpath, bfad->pci_name);
> - for (i = 0; iocmd->adapter_hwpath[i] != ':' && i < BFA_STRING_32; i++)
> - ;
> - for (; iocmd->adapter_hwpath[++i] != ':' && i < BFA_STRING_32; )
> - ;
> + i = -1;
> + while (++i < BFA_STRING_32) {
> + if (iocmd->adapter_hwpath[i] == ':')
> + break;
> + }
> + while (++i < BFA_STRING_32) {
> + if (iocmd->adapter_hwpath[i] == ':')
> + break;
> + }
> + if (i >= BFA_STRING_32)
> + i = BFA_STRING_32 - 1;
> iocmd->adapter_hwpath[i] = '\0';
> iocmd->status = BFA_STATUS_OK;
> return 0;
I do not see the use case but i assume
the idea is to have a string like aa:bb:something
and kill everyhing after the second ':' ?
/*
a few word may help here also inside the code
*/
second: maybe we can us strchr here ?
s1=strchr(iocmd->adapter_hwpath,':');
if (s1 != NULL ) s1=strchr(s1,":");
re,
wh
next prev parent reply other threads:[~2016-06-16 12:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 10:44 [patch] bfa: clean up some bounds checking Dan Carpenter
2016-06-16 10:44 ` Dan Carpenter
2016-06-16 12:20 ` walter harms [this message]
2016-06-16 12:20 ` walter harms
2016-07-01 13:12 ` Sudarsana Kalluru
2016-07-01 13:12 ` Sudarsana Kalluru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5762997D.3020302@bfs.de \
--to=wharms@bfs.de \
--cc=anil.gurumurthy@qlogic.com \
--cc=dan.carpenter@oracle.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sudarsana.kalluru@qlogic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.