Skip to content

Commit

Permalink
cmds: fix abstract socket length problem
Browse files Browse the repository at this point in the history
Since we want to use null-terminated abstract sockets, let's compute the length
of them correctly.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
Tycho Andersen authored and stgraber committed Sep 25, 2015
1 parent 8fafe2d commit 6f2944c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lxc/commands.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 6f2944c

Please sign in to comment.