diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 663f59a9b..89f4b2f06 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -215,7 +215,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle if (path[0]) { ret = snprintf(tempname, maxpathlen, "%s.%d.tmp", path, pid); - if (ret < 0 || ret >= maxpathlen) { + if (ret < 0 || ret >= sizeof(addr.sun_path)) { err |= ERR_FATAL | ERR_ALERT; msg = "name too long for UNIX socket (limit usually 97)"; goto err_return; @@ -248,6 +248,18 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle goto err_return; } + /* Note: this test is redundant with the snprintf one above and + * will never trigger, it's just added as the only way to shut + * gcc's painfully dumb warning about possibly truncated output + * during strncpy(). Don't move it above or smart gcc will not + * see it! + */ + if (strlen(tempname) >= sizeof(addr.sun_path)) { + err |= ERR_FATAL | ERR_ALERT; + msg = "name too long for UNIX socket (limit usually 97)"; + goto err_return; + } + strncpy(addr.sun_path, tempname, sizeof(addr.sun_path) - 1); addr.sun_path[sizeof(addr.sun_path) - 1] = 0; }