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

From:
Bryan Steele <brynet@gmail.com>
Subject:
Re: replace malloc+memcpy with strndup
To:
gameoftrees@openbsd.org
Date:
Tue, 10 Jan 2023 15:05:07 -0500

Download raw body.

Thread
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?
> 
> ...
> blob - a6b8f011af70edd6ca8e1dd6ffc0658788c67ad1
> blob + 4d1f43e554adcd668e7e8663eb9ffcb861dad3e6
> --- gotd/session.c
> +++ gotd/session.c
> @@ -419,11 +419,9 @@ update_ref(struct gotd_session_client *client, const c
>  	memcpy(&iref, imsg->data, sizeof(iref));
>  	if (datalen != sizeof(iref) + iref.name_len)
>  		return got_error(GOT_ERR_PRIVSEP_LEN);
> -	refname = malloc(iref.name_len + 1);
> +	refname = strndup(imsg->data + sizeof(iref), iref.name_len);
>  	if (refname == NULL)
> -		return got_error_from_errno("malloc");
> -	memcpy(refname, imsg->data + sizeof(iref), iref.name_len);
> -	refname[iref.name_len] = '\0';
> +		return got_error_from_errno("strndup");
>  
>  	log_debug("updating ref %s for uid %d", refname, client->euid);
>  
> @@ -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. :-)