Throw error on too long unix domain socket file path (#9826)

* Fix too long unix domain socket file path

Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
This commit is contained in:
ranshid 2021-12-16 07:38:45 +02:00 committed by GitHub
parent 867816003e
commit 28b5a6537d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -479,6 +479,10 @@ int anetUnixServer(char *err, char *path, mode_t perm, int backlog)
int s;
struct sockaddr_un sa;
if (strlen(path) > sizeof(sa.sun_path)-1) {
anetSetError(err,"unix socket path too long (%zu), must be under %zu", strlen(path), sizeof(sa.sun_path));
return ANET_ERR;
}
if ((s = anetCreateSocket(err,AF_LOCAL)) == ANET_ERR)
return ANET_ERR;

View File

@ -2281,7 +2281,7 @@ void initServer(void) {
server.sofd = anetUnixServer(server.neterr,server.unixsocket,
(mode_t)server.unixsocketperm, server.tcp_backlog);
if (server.sofd == ANET_ERR) {
serverLog(LL_WARNING, "Opening Unix socket: %s", server.neterr);
serverLog(LL_WARNING, "Failed opening Unix socket: %s", server.neterr);
exit(1);
}
anetNonBlock(NULL,server.sofd);
@ -3518,7 +3518,8 @@ void closeListeningSockets(int unlink_unix_socket) {
for (j = 0; j < server.cfd.count; j++) close(server.cfd.fd[j]);
if (unlink_unix_socket && server.unixsocket) {
serverLog(LL_NOTICE,"Removing the unix socket file.");
unlink(server.unixsocket); /* don't care if this fails */
if (unlink(server.unixsocket) != 0)
serverLog(LL_WARNING,"Error removing the unix socket file: %s",strerror(errno));
}
}