From: Stefan Sperling Subject: Re: replace malloc+memcpy with strndup To: Omar Polo Cc: Bryan Steele , gameoftrees@openbsd.org Date: Tue, 10 Jan 2023 23:26:16 +0100 On Tue, Jan 10, 2023 at 11:10:01PM +0100, Omar Polo wrote: > On 2023/01/10 15:05:07 -0500, Bryan Steele 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.