Skip to content

Commit 1cc15b8

Browse files
committed
Fix issues with error checking on socket() and bind() length
1 parent 82c03c1 commit 1cc15b8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/wdctl_thread.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ thread_wdctl(void *arg)
9292

9393

9494
debug(LOG_DEBUG, "Creating socket");
95-
wdctl_socket_server = socket(PF_UNIX, SOCK_STREAM, 0);
95+
if (-1 == (wdctl_socket_server = socket(PF_UNIX, SOCK_STREAM, 0))) {
96+
debug(LOG_ERR, "Could not created wdctl socket (%s)", strerror(errno));
97+
exit(1);
98+
}
9699

97100
debug(LOG_DEBUG, "Got server socket %d", wdctl_socket_server);
98101

@@ -283,7 +286,10 @@ wdctl_restart(int afd)
283286
}
284287

285288
debug(LOG_DEBUG, "Creating socket");
286-
sock = socket(PF_UNIX, SOCK_STREAM, 0);
289+
if (-1 == (sock = socket(PF_UNIX, SOCK_STREAM, 0))) {
290+
debug(LOG_ERR, "Could not created wdctl socket (%s)", strerror(errno));
291+
exit(1);
292+
}
287293

288294
debug(LOG_DEBUG, "Got internal socket %d", sock);
289295

@@ -297,7 +303,7 @@ wdctl_restart(int afd)
297303
debug(LOG_DEBUG, "Binding socket (%s) (%d)", sa_un.sun_path, strlen(sock_name));
298304

299305
/* Which to use, AF_UNIX, PF_UNIX, AF_LOCAL, PF_LOCAL? */
300-
if (-1 == bind(wdctl_socket_server, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
306+
if (-1 == bind(sock, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
301307
debug(LOG_ERR, "Could not bind internal socket: %s", strerror(errno));
302308
return;
303309
}

0 commit comments

Comments
 (0)