]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
monitor: fix sockname calculation for long lxcpaths
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Sat, 9 Aug 2014 00:30:12 +0000 (00:30 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 18 Aug 2014 03:39:02 +0000 (23:39 -0400)
A long enough lxcpath (and small PATH_MAX through crappy defines) can cause
the creation of the string to be hashed to fail.  So just use alloca to
get the size string we need.

More importantly, while I can't explain it, if lxcpath is too long, setting
sockname[sizeof(addr->sun_path)-2] to \0 simply doesn't seem to work.  So set
sockname[sizeof(addr->sun_path)-3] to \0, which does work.

With this, and with

lxc.lxcpath = /opt/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789

in /etc/lxc/lxc.conf, I can run lxc-wait just fine.  Without it, it fails
(as does lxc-start -d, which uses lxc_wait to verify the container started)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/monitor.c

index 7c6dbb4a565cefaa658fe7fef23953f8f69d984c..59b02b3b90a28661d56dbfff5aea4a7344837994 100644 (file)
@@ -142,7 +142,7 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) {
        size_t len;
        int ret;
        char *sockname = &addr->sun_path[1];
-       char path[PATH_MAX+18];
+       char *path;
        uint64_t hash;
 
        /* addr.sun_path is only 108 bytes, so we hash the full name and
@@ -150,18 +150,20 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) {
         */
        memset(addr, 0, sizeof(*addr));
        addr->sun_family = AF_UNIX;
-       len = sizeof(addr->sun_path) - 1;
-       ret = snprintf(path, sizeof(path), "lxc/%s/monitor-sock", lxcpath);
-       if (ret < 0 || ret >= sizeof(path)) {
-               ERROR("lxcpath %s too long for monitor unix socket", lxcpath);
+       len = strlen(lxcpath) + 18;
+       path = alloca(len);
+       ret = snprintf(path, len, "lxc/%s/monitor-sock", lxcpath);
+       if (ret < 0 || ret >= len) {
+               ERROR("memory error creating monitor path");
                return -1;
        }
 
+       len = sizeof(addr->sun_path) - 1;
        hash = fnv_64a_buf(path, ret, FNV1A_64_INIT);
        ret = snprintf(sockname, len, "lxc/%016" PRIx64 "/%s", hash, lxcpath);
        if (ret < 0)
                return -1;
-       sockname[sizeof(addr->sun_path)-2] = '\0';
+       sockname[sizeof(addr->sun_path)-3] = '\0';
        INFO("using monitor sock name %s", sockname);
        return 0;
 }