]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands_utils: fix command socket hashing 3287/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 11 Mar 2020 01:59:36 +0000 (02:59 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 11 Mar 2020 01:59:36 +0000 (02:59 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands_utils.c

index b83b811becc213a6ab00ccd200ace7a08b7c259d..884a18ea1c485407913301c89c1c036af6966c7c 100644 (file)
@@ -114,22 +114,25 @@ int lxc_make_abstract_socket_name(char *path, size_t pathlen,
        }
 
        ret = snprintf(offset, len, "%s/%s/%s", lxcpath, name, suffix);
-       if (ret < 0 || (size_t)ret >= len)
+       if (ret < 0)
                return log_error_errno(-1, errno, "Failed to create abstract socket name");
-       if (ret < len)
-               return 0;
 
-       /* ret >= len; lxcpath or name is too long.  hash both */
-       tmplen = strlen(name) + strlen(lxcpath) + 2;
-       tmppath = must_realloc(NULL, tmplen);
-       ret = snprintf(tmppath, tmplen, "%s/%s", lxcpath, name);
-       if (ret < 0 || (size_t)ret >= tmplen)
-               return log_error_errno(-1, errno, "Failed to create abstract socket name");
+       /*
+        * ret >= len. This means lxcpath and name are too long. We need to
+        * hash both.
+        */
+       if (ret >= len) {
+               tmplen = strlen(name) + strlen(lxcpath) + 2;
+               tmppath = must_realloc(NULL, tmplen);
+               ret = snprintf(tmppath, tmplen, "%s/%s", lxcpath, name);
+               if (ret < 0 || (size_t)ret >= tmplen)
+                       return log_error_errno(-1, errno, "Failed to create abstract socket name");
 
-       hash = fnv_64a_buf(tmppath, ret, FNV1A_64_INIT);
-       ret = snprintf(offset, len, "lxc/%016" PRIx64 "/%s", hash, suffix);
-       if (ret < 0 || ret >= len)
-               return log_error_errno(-1, errno, "Failed to create abstract socket name");
+               hash = fnv_64a_buf(tmppath, ret, FNV1A_64_INIT);
+               ret = snprintf(offset, len, "lxc/%016" PRIx64 "/%s", hash, suffix);
+               if (ret < 0 || (size_t)ret >= len)
+                       return log_error_errno(-1, errno, "Failed to create abstract socket name");
+       }
 
        return 0;
 }