summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Sowden <jeremy@azazel.net>2021-11-30 10:55:36 +0000
committerPablo Neira Ayuso <pablo@netfilter.org>2021-11-30 20:55:17 +0100
commit103a52a1b09991d88ff38991b6b6837a1dd0a1ab (patch)
tree05f7ab9137aa0408bdba000244c01073631310fa
parentae3d0f59e2d1962d2a8f97dfb3e05b32ca11ea82 (diff)
input: UNIXSOCK: remove stat of socket-path
When creating the UNIX socket, there is a TOCTOU race between the stat(2) and bind(2) calls, and if the path is already bound, the bind(2) call will fail in any case. Remove the stat(2) call. Tidy up a couple of error message. Signed-off-by: Jeremy Sowden <jeremy@azazel.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--input/packet/ulogd_inppkt_UNIXSOCK.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/input/packet/ulogd_inppkt_UNIXSOCK.c b/input/packet/ulogd_inppkt_UNIXSOCK.c
index 86ab590..3f3abc3 100644
--- a/input/packet/ulogd_inppkt_UNIXSOCK.c
+++ b/input/packet/ulogd_inppkt_UNIXSOCK.c
@@ -477,12 +477,11 @@ static int _create_unix_socket(const char *unix_path)
int ret = -1;
struct sockaddr_un server_sock;
int s;
- struct stat st_dummy;
s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0) {
ulogd_log(ULOGD_ERROR,
- "ulogd2: could not create unix socket\n");
+ "ulogd2: could not create unix socket\n");
return -1;
}
@@ -490,19 +489,11 @@ static int _create_unix_socket(const char *unix_path)
strncpy(server_sock.sun_path, unix_path, sizeof(server_sock.sun_path));
server_sock.sun_path[sizeof(server_sock.sun_path)-1] = '\0';
- if (stat(unix_path, &st_dummy) == 0 && st_dummy.st_size > 0) {
- ulogd_log(ULOGD_ERROR,
- "ulogd2: unix socket \'%s\' already exists\n",
- unix_path);
- close(s);
- return -1;
- }
-
ret = bind(s, (struct sockaddr *)&server_sock, sizeof(server_sock));
if (ret < 0) {
ulogd_log(ULOGD_ERROR,
- "ulogd2: could not bind to unix socket \'%s\'\n",
- server_sock.sun_path);
+ "ulogd2: could not bind to unix socket '%s'\n",
+ server_sock.sun_path);
close(s);
return -1;
}
@@ -510,8 +501,8 @@ static int _create_unix_socket(const char *unix_path)
ret = listen(s, 10);
if (ret < 0) {
ulogd_log(ULOGD_ERROR,
- "ulogd2: could not bind to unix socket \'%s\'\n",
- server_sock.sun_path);
+ "ulogd2: could not listen to unix socket '%s'\n",
+ server_sock.sun_path);
close(s);
return -1;
}