public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] serial-uclass.c: Copy at most sdev.name - 1 characters into the buffer
Date: Tue, 8 Dec 2015 18:32:55 -0500	[thread overview]
Message-ID: <20151208233255.GG667@bill-the-cat> (raw)
In-Reply-To: <CAPnjgZ0k8MwFUR9tEtM0eiFPMcWFnVe7--uGT62dFn__a_gEyw@mail.gmail.com>

On Tue, Dec 08, 2015 at 12:35:18PM -0700, Simon Glass wrote:
> On 7 December 2015 at 20:26, Tom Rini <trini@konsulko.com> wrote:
> > Coverity notes that we do not ensure a NULL terminated string here as we
> > could fill the entire buffer with our strncpy call.  Fix this by
> > subtracting one.
> >
> > Reported-by: Coverity (CID 131093)
> > Cc: Simon Glass <sjg@chromium.org>
> > Signed-off-by: Tom Rini <trini@konsulko.com>
> > ---
> >  drivers/serial/serial-uclass.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> >
> > diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
> > index 842f78b..2ef82b0 100644
> > --- a/drivers/serial/serial-uclass.c
> > +++ b/drivers/serial/serial-uclass.c
> > @@ -324,7 +324,7 @@ static int serial_post_probe(struct udevice *dev)
> >                 return 0;
> >         memset(&sdev, '\0', sizeof(sdev));
> >
> > -       strncpy(sdev.name, dev->name, sizeof(sdev.name));
> > +       strncpy(sdev.name, dev->name, sizeof(sdev.name) - 1);
> 
> There is also strlcpy() if you want it.

Ah good.  Yeah, I think I should v2 this patch and use strlcpy as
there's going to be many more of these I bet to come.

-- 
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/545774f7/attachment.sig>

      reply	other threads:[~2015-12-08 23:32 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
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 [this message]

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=20151208233255.GG667@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox