]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cmds: fix abstract socket length problem
authorTycho Andersen <tycho.andersen@canonical.com>
Fri, 25 Sep 2015 22:45:59 +0000 (16:45 -0600)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 25 Sep 2015 22:52:32 +0000 (18:52 -0400)
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>
src/lxc/commands.c

index b70ee722632209ed6bd45efff0771aa4d6d0ad24..a807da38e131bf6dffc8c3110edeac09184a6faa 100644 (file)
@@ -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;