qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [5532] Replace uses of strndup (a GNU extension) with Q


From: Warner Losh
Subject: Re: [Qemu-devel] [5532] Replace uses of strndup (a GNU extension) with Qemu pstrdup
Date: Sat, 25 Oct 2008 17:58:38 -0600 (MDT)

From: "andrzej zaborowski" <address@hidden>
Subject: Re: [Qemu-devel] [5532] Replace uses of strndup (a GNU extension) with 
Qemu pstrdup
Date: Sat, 25 Oct 2008 14:03:40 +0200

> 2008/10/25 Blue Swirl <address@hidden>:
> > Revision: 5532
> >          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5532
> > Author:   blueswir1
> > Date:     2008-10-25 11:23:27 +0000 (Sat, 25 Oct 2008)
> >
> > Log Message:
> > -----------
> > Replace uses of strndup (a GNU extension) with Qemu pstrdup
> >
> > Modified Paths:
> > --------------
> >    trunk/cutils.c
> >    trunk/hw/bt-hci.c
> >    trunk/qemu-common.h
> >
> > Modified: trunk/cutils.c
> > ===================================================================
> > --- trunk/cutils.c      2008-10-25 11:21:28 UTC (rev 5531)
> > +++ trunk/cutils.c      2008-10-25 11:23:27 UTC (rev 5532)
> > @@ -50,6 +50,18 @@
> >     return buf;
> >  }
> >
> > +/* strdup with a limit */
> > +char *pstrdup(const char *str, size_t buf_size)
> > +{
> > +    size_t len;
> > +    char *buf;
> > +
> > +    len = MIN(buf_size, strlen(str));
> > +    buf = qemu_malloc(len);
> > +    pstrcpy(buf, len, str);
> > +    return buf;
> > +}
> 
> I think here also pstrcpy will only copy up to buf_size - 1 characters
> while strndup would copy buf_size chars.

Is this really safe?  If str is very long, this can still run off into
the weeds...

Warner




reply via email to

[Prev in Thread] Current Thread [Next in Thread]