die with sensible error message if socket path too long

This commit is contained in:
2026-05-18 23:26:48 +01:00
parent 9569ba3cfa
commit 262fc6437c
+5 -1
View File
@@ -32,7 +32,11 @@ static void handle_sigchld(int num) {
int open_socket(char * pathname) {
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, pathname, sizeof(addr.sun_path) - 1);
if(strlen(pathname) > sizeof(addr.sun_path)) {
die("pathname \"%s\" is too long to bind as unix socket (max %lu)",
pathname, sizeof(addr.sun_path));
}
strcpy(addr.sun_path, pathname);
int fd = socket(AF_LOCAL, SOCK_DGRAM, PF_LOCAL);
if(fd < 0) {