From 1694bcc9b3a12f8265cc163edb21212023e7b538 Mon Sep 17 00:00:00 2001 From: bbergeron Date: Tue, 21 May 2024 23:18:35 -0400 Subject: Add comment regarding named socket length --- main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 7899b7b..ee72824 100644 --- a/main.c +++ b/main.c @@ -121,9 +121,17 @@ int get_socket_fd (const char *socketname, int as_daemon) int fd; struct sockaddr_un addr; - // TODO: Re-check the documentation apropos socket name length + /* UNIX domain socket name lengths are limited to "sizeof(sun_path)", which + * varies from one system to another. A partial solution would be to call + * "chdir" to trim out the directory part of the socket name and use a + * relative path, but the file part of the socket could still be too large + * for sockaddr_un. + * + * It's easier to check the socket length and simply reject names that would + * overflow the buffer. + */ if (strlen(socketname) > sizeof(addr.sun_path) - 1) { - fputs("Failed to create socket: filename too long\n", stderr); + fputs("Cannot create or open socket: Filename too long\n", stderr); return -1; } -- cgit v1.2.3