die with sensible error message if socket path too long
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user