All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: walter harms <wharms@bfs.de>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>,
	linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] [media] media: info leak in media_device_enum_entities()
Date: Sun, 21 Apr 2013 16:42:56 +0000	[thread overview]
Message-ID: <20130421164256.GM6638@mwanda> (raw)
In-Reply-To: <5173D2DC.4060200@bfs.de>

On Sun, Apr 21, 2013 at 01:51:56PM +0200, walter harms wrote:
> 
> 
> Am 21.04.2013 13:10, schrieb Dan Carpenter:
> > The last part of the "u_ent.name" buffer isn't cleared so it still has
> > uninitialized stack memory.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 99b80b6..1957c0d 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -102,9 +102,12 @@ static long media_device_enum_entities(struct media_device *mdev,
> >  		return -EINVAL;
> >  
> >  	u_ent.id = ent->id;
> > -	u_ent.name[0] = '\0';
> > -	if (ent->name)
> > -		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
> > +	if (ent->name) {
> > +		strncpy(u_ent.name, ent->name, sizeof(u_ent.name));
> > +		u_ent.name[sizeof(u_ent.name) - 1] = '\0';
> > +	} else {
> > +		memset(u_ent.name, 0, sizeof(u_ent.name));
> > +	}
> 
> I would always memset()
> and then do strncpy() for sizeof(u_ent.name) - 1
> the rest is always zero.

Both ways are fine.  You'd still have to test for "if (ent->name)",
of course.  This way is a little faster because I do the test first.

Mauro, if you want I can redo it?

regards,
dan carpenter


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: walter harms <wharms@bfs.de>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>,
	linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] [media] media: info leak in media_device_enum_entities()
Date: Sun, 21 Apr 2013 19:42:56 +0300	[thread overview]
Message-ID: <20130421164256.GM6638@mwanda> (raw)
In-Reply-To: <5173D2DC.4060200@bfs.de>

On Sun, Apr 21, 2013 at 01:51:56PM +0200, walter harms wrote:
> 
> 
> Am 21.04.2013 13:10, schrieb Dan Carpenter:
> > The last part of the "u_ent.name" buffer isn't cleared so it still has
> > uninitialized stack memory.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 99b80b6..1957c0d 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -102,9 +102,12 @@ static long media_device_enum_entities(struct media_device *mdev,
> >  		return -EINVAL;
> >  
> >  	u_ent.id = ent->id;
> > -	u_ent.name[0] = '\0';
> > -	if (ent->name)
> > -		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
> > +	if (ent->name) {
> > +		strncpy(u_ent.name, ent->name, sizeof(u_ent.name));
> > +		u_ent.name[sizeof(u_ent.name) - 1] = '\0';
> > +	} else {
> > +		memset(u_ent.name, 0, sizeof(u_ent.name));
> > +	}
> 
> I would always memset()
> and then do strncpy() for sizeof(u_ent.name) - 1
> the rest is always zero.

Both ways are fine.  You'd still have to test for "if (ent->name)",
of course.  This way is a little faster because I do the test first.

Mauro, if you want I can redo it?

regards,
dan carpenter


  reply	other threads:[~2013-04-21 16:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-21 11:10 [patch] [media] media: info leak in media_device_enum_entities() Dan Carpenter
2013-04-21 11:10 ` Dan Carpenter
2013-04-21 11:51 ` walter harms
2013-04-21 11:51   ` walter harms
2013-04-21 16:42   ` Dan Carpenter [this message]
2013-04-21 16:42     ` Dan Carpenter

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=20130421164256.GM6638@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=wharms@bfs.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.