[lxc-devel] [PATCH] cmds: fix abstract socket length problem

Stéphane Graber stgraber at ubuntu.com
Fri Sep 25 22:51:15 UTC 2015


On Fri, Sep 25, 2015 at 04:45:59PM -0600, Tycho Andersen wrote:
> Since we want to use null-terminated abstract sockets, let's compute the length
> of them correctly.
> 
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

> ---
>  src/lxc/commands.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/commands.c b/src/lxc/commands.c
> index b70ee72..a807da3 100644
> --- a/src/lxc/commands.c
> +++ b/src/lxc/commands.c
> @@ -279,7 +279,12 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped,
>  
>  	*stopped = 0;
>  
> -	len = sizeof(path)-1;
> +	/* -2 here because this is an abstract unix socket so it needs a
> +	 * leading \0, and we null terminate, so it needs a trailing \0.
> +	 * Although null termination isn't required by the API, we do it anyway
> +	 * because we print the sockname out sometimes.
> +	 */
> +	len = sizeof(path)-2;
>  	if (fill_sock_name(offset, len, name, lxcpath, hashed_sock_name))
>  		return -1;
>  
> @@ -972,7 +977,12 @@ int lxc_cmd_init(const char *name, struct lxc_handler *handler,
>  	char *offset = &path[1];
>  	int len;
>  
> -	len = sizeof(path)-1;
> +	/* -2 here because this is an abstract unix socket so it needs a
> +	 * leading \0, and we null terminate, so it needs a trailing \0.
> +	 * Although null termination isn't required by the API, we do it anyway
> +	 * because we print the sockname out sometimes.
> +	 */
> +	len = sizeof(path)-2;
>  	if (fill_sock_name(offset, len, name, lxcpath, NULL))
>  		return -1;
>  
> -- 
> 2.1.4
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150925/36b6f272/attachment.sig>


More information about the lxc-devel mailing list