All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/3] sandbox: sandbox_flash.c: Ensure NUL-termination on product/vendor strings
Date: Tue, 8 Dec 2015 18:28:34 -0500	[thread overview]
Message-ID: <20151208232834.GF667@bill-the-cat> (raw)
In-Reply-To: <CAPnjgZ1XR28uOseFkmgzELkHJTRZVhPD_rz5mMpdQM5SEFRLiA@mail.gmail.com>

On Tue, Dec 08, 2015 at 12:35:23PM -0700, Simon Glass wrote:
> Hi Tom,
> 
> On 7 December 2015 at 20:26, Tom Rini <trini@konsulko.com> wrote:
> > Coverity notes that we do not ensure when we copy in the product/vendor
> > strings that they have NULL termination.  In this case the answer is to
> > increase the buffer we have and then set the last entry to NULL.
> >
> > Reported-by: Coverity (CID 131095)
> > Cc: Simon Glass <sjg@chromium.org>
> > Signed-off-by: Tom Rini <trini@konsulko.com>
> > ---
> >  drivers/usb/emul/sandbox_flash.c |    6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c
> > index 0965ad0..2811f52 100644
> > --- a/drivers/usb/emul/sandbox_flash.c
> > +++ b/drivers/usb/emul/sandbox_flash.c
> > @@ -79,8 +79,8 @@ struct scsi_inquiry_resp {
> >         u8 data_format;
> >         u8 additional_len;
> >         u8 spare[3];
> > -       char vendor[8];
> > -       char product[16];
> > +       char vendor[9]; /* 8 + NUL-termination */
> > +       char product[17]; /* 16 + NUL-termination */
> >         char revision[4];
> >  };
> >
> > @@ -260,6 +260,8 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
> >                 strncpy(resp->product,
> >                         plat->flash_strings[STRINGID_PRODUCT - 1].s,
> >                         sizeof(resp->product));
> > +               resp->vendor[8] = 0;
> > +               resp->product[16] = 0;
> >                 strncpy(resp->revision, "1.0", sizeof(resp->revision));
> >                 setup_response(priv, resp, sizeof(*resp));
> >                 break;
> > --
> > 1.7.9.5
> >
> 
> Does this work? It seems like it is changing the SCSI protocol spec,
> which we can't do.

Yes.  We memset resp to NULL to start with so we know it will always be
NULL terminated now.  Elsewhere in our SCSI code is where I got the
idea, common/usb_storage.c::usb_stor_get_info for example.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151208/ee594076/attachment.sig>

  reply	other threads:[~2015-12-08 23:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08  3:26 [U-Boot] [PATCH 1/3] serial-uclass.c: Copy at most sdev.name - 1 characters into the buffer Tom Rini
2015-12-08  3:26 ` [U-Boot] [PATCH 2/3] sandbox: eth-raw-os.c: Ensure that our interface name is not too long Tom Rini
2015-12-08 19:35   ` Simon Glass
2015-12-19 22:23     ` Simon Glass
2015-12-08  3:26 ` [U-Boot] [PATCH 3/3] sandbox: sandbox_flash.c: Ensure NUL-termination on product/vendor strings Tom Rini
2015-12-08 19:35   ` Simon Glass
2015-12-08 23:28     ` Tom Rini [this message]
2015-12-08 23:42       ` Simon Glass
2015-12-08 23:58         ` Tom Rini
2015-12-09 23:58           ` Simon Glass
2015-12-10  1:01             ` Tom Rini
2015-12-08 19:35 ` [U-Boot] [PATCH 1/3] serial-uclass.c: Copy at most sdev.name - 1 characters into the buffer Simon Glass
2015-12-08 23:32   ` Tom Rini

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=20151208232834.GF667@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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.