From 917a51a406c7c5223dc4212737641859b210c629 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 28 Apr 2021 08:37:23 -0400 Subject: [PATCH] Error if bind to privileged port fails --- confluent_osdeploy/utils/clortho.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/confluent_osdeploy/utils/clortho.c b/confluent_osdeploy/utils/clortho.c index 5cff7c6e..ef58e6b8 100644 --- a/confluent_osdeploy/utils/clortho.c +++ b/confluent_osdeploy/utils/clortho.c @@ -82,9 +82,15 @@ int main(int argc, char* argv[]) { if (sock < 0) continue; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); if (curr->ai_family == AF_INET) { - bind(sock, (struct sockaddr*)&net4bind, sizeof(struct sockaddr_in)); + if (bind(sock, (struct sockaddr*)&net4bind, sizeof(struct sockaddr_in)) < 0) { + fprintf(stderr, "Unable to bind port 302\n"); + exit(1); + } } else if (curr->ai_family == AF_INET6) { - bind(sock, (struct sockaddr*)&net6bind, sizeof(struct sockaddr_in6)); + if (bind(sock, (struct sockaddr*)&net6bind, sizeof(struct sockaddr_in6)) < 0) { + fprintf(stderr, "Unable to bind port 302\n"); + exit(1); + } } else { continue; }