threads / patch / 41985

patch, 3 partsindex-helper: convert strncpy to memcpy

Subject: [PATCH 2/3] index-helper: convert strncpy to memcpy

## tl;dr

2 messages between Apr 10, 2016 and Apr 11, 2016. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Ramsay Jones· Apr 10, 2016, 23:02 UTC · lore
see commit eddda371 ("convert strncpy to memcpy", 24-09-2015).
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 index-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to index-helper.c +1 −1
diff --git a/index-helper.c b/index-helper.c
index 4a8e2ae..00f286a 100644
--- a/index-helper.c
+++ b/index-helper.c
@@ -317,7 +317,7 @@ static int setup_socket(const char *socket_path)
 		return -1;
 
 	address.sun_family = AF_UNIX;
-	strncpy(address.sun_path, socket_path, sizeof(address.sun_path));
+	memcpy(address.sun_path, socket_path, len+1); /* include '\0' */
 
 	if (bind(fd, (struct sockaddr *) &address, sizeof(address)))
 		die_errno(_("failed to bind to socket %s"), socket_path);
-- 
2.8.0
David Turner· Apr 11, 2016, 22:30 UTC · re: Ramsay Jones · lore

Re: [PATCH 2/3] index-helper: convert strncpy to memcpy

On Mon, 2016-04-11 at 00:02 +0100, Ramsay Jones wrote:
Show 23 quoted lines
> see commit eddda371 ("convert strncpy to memcpy", 24-09-2015).
> 
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
> ---
>  index-helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/index-helper.c b/index-helper.c
> index 4a8e2ae..00f286a 100644
> --- a/index-helper.c
> +++ b/index-helper.c
> @@ -317,7 +317,7 @@ static int setup_socket(const char *socket_path)
>  		return -1;
>  
>  	address.sun_family = AF_UNIX;
> -	strncpy(address.sun_path, socket_path,
> sizeof(address.sun_path));
> +	memcpy(address.sun_path, socket_path, len+1); /* include
> '\0' */
>  
>  	if (bind(fd, (struct sockaddr *) &address, sizeof(address)))
>  		die_errno(_("failed to bind to socket %s"),
> socket_path);
Thanks. 

I'm actually going to drop this patch because I'm switching to the unix -socket.c helpers, so the affected code no longer exists. But I appreciate the thought anyway.

← back to recent threads