"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: replace malloc+memcpy with strndup
To:
Omar Polo <op@omarpolo.com>
Cc:
Bryan Steele <brynet@gmail.com>, gameoftrees@openbsd.org
Date:
Tue, 10 Jan 2023 23:26:16 +0100

Download raw body.

Thread
On Tue, Jan 10, 2023 at 11:10:01PM +0100, Omar Polo wrote:
> On 2023/01/10 15:05:07 -0500, Bryan Steele <brynet@gmail.com> wrote:
> > On Tue, Jan 10, 2023 at 07:11:00PM +0100, Omar Polo wrote:
> > > as per subject.  no functional change intended, just shorten some
> > > chunks of code
> > > 
> > > ok?
> > > 
> > > ...
> > > @@ -667,25 +665,18 @@ recv_capability(struct gotd_session_client *client, st
> > >  	if (datalen != sizeof(icapa) + icapa.key_len + icapa.value_len)
> > >  		return got_error(GOT_ERR_PRIVSEP_LEN);
> > >  
> > > -	key = malloc(icapa.key_len + 1);
> > > +	key = strndp(imsg->data + sizeof(icapa), icapa.key_len);
> > 
> > Typo here, but you probably already noticed. :-)
> 
> No idea how that ended up there.  there was another typo in the diff,
> sorry.  Probably i've forgot to rebuild gotd after the first sweep.
> 
> updated and recheked diff, this one should be fine :)
> 
> thanks!

Makes sense, ok.
I don't think any of these buffers contain data expected to contain
embedded NULs, which would be a reason to keep using mempcy.