Skip to content

Commit 82c03c1

Browse files
committed
Fix error checking for bind
1 parent d50b42b commit 82c03c1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/wdctl_thread.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ thread_wdctl(void *arg)
108108
strlen(sock_name));
109109

110110
/* Which to use, AF_UNIX, PF_UNIX, AF_LOCAL, PF_LOCAL? */
111-
if (bind(wdctl_socket_server, (struct sockaddr *)&sa_un, strlen(sock_name)
112-
+ sizeof(sa_un.sun_family))) {
111+
if (-1 == bind(wdctl_socket_server, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
113112
debug(LOG_ERR, "Could not bind control socket: %s",
114113
strerror(errno));
115114
pthread_exit(NULL);
@@ -298,7 +297,7 @@ wdctl_restart(int afd)
298297
debug(LOG_DEBUG, "Binding socket (%s) (%d)", sa_un.sun_path, strlen(sock_name));
299298

300299
/* Which to use, AF_UNIX, PF_UNIX, AF_LOCAL, PF_LOCAL? */
301-
if (bind(sock, (struct sockaddr *)&sa_un, strlen(sock_name) + sizeof(sa_un.sun_family))) {
300+
if (-1 == bind(wdctl_socket_server, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
302301
debug(LOG_ERR, "Could not bind internal socket: %s", strerror(errno));
303302
return;
304303
}

0 commit comments

Comments
 (0)