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;
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;
}