From: 2xsec Date: Fri, 12 Oct 2018 02:19:04 +0000 (+0900) Subject: monitor: checking name too long to make monitor sock name X-Git-Tag: lxc-3.1.0~48^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f1264995f17ddb206164b31c1b2b222e4913f3a;p=thirdparty%2Flxc.git monitor: checking name too long to make monitor sock name Signed-off-by: 2xsec --- diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index ef21457c3..64dd3511e 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -199,7 +199,11 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) { ret = snprintf(addr->sun_path, len, "@lxc/%016" PRIx64 "/%s", hash, lxcpath); if (ret < 0) { ERROR("Failed to create hashed name for monitor socket"); - return -1; + goto on_error; + } else if ((size_t)ret >= len) { + errno = ENAMETOOLONG; + SYSERROR("The name of monitor socket too long (%d bytes)", ret); + goto on_error; } /* replace @ with \0 */ @@ -207,6 +211,9 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) { INFO("Using monitor socket name \"%s\" (length of socket name %zu must be <= %zu)", &addr->sun_path[1], strlen(&addr->sun_path[1]), sizeof(addr->sun_path) - 3); return 0; + +on_error: + return -1; } int lxc_monitor_open(const char *lxcpath) @@ -214,19 +221,12 @@ int lxc_monitor_open(const char *lxcpath) struct sockaddr_un addr; int fd; size_t retry; - size_t len; int backoff_ms[] = {10, 50, 100}; if (lxc_monitor_sock_name(lxcpath, &addr) < 0) return -1; - len = strlen(&addr.sun_path[1]); - DEBUG("Opening monitor socket %s with len %zu", &addr.sun_path[1], len); - if (len >= sizeof(addr.sun_path) - 1) { - errno = ENAMETOOLONG; - SYSERROR("The name of monitor socket too long (%zu bytes)", len); - return -1; - } + DEBUG("Opening monitor socket %s with len %zu", &addr.sun_path[1], strlen(&addr.sun_path[1])); for (retry = 0; retry < sizeof(backoff_ms) / sizeof(backoff_ms[0]); retry++) { fd = lxc_abstract_unix_connect(addr.sun_path);