From 438db2ee8b5f300d7bd3014b023297f1019c7816 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Thu, 4 Apr 2024 12:04:43 +0200 Subject: [PATCH] [#426] Fix a problem in `pgagroal_bind` If the configuration `host` is set to `*`, meaning all the interfaces, the `pgagroal_bind` function was always returning a true value even if no available bind addresses were left. In order to fix this, the commit tests if the `star_length` variable has been set to something non-zero, otherwise no more sockets are available (bound) and the function returns a `1` to indicate an error. Close #426 --- src/libpgagroal/network.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libpgagroal/network.c b/src/libpgagroal/network.c index b37ffee..21bc258 100644 --- a/src/libpgagroal/network.c +++ b/src/libpgagroal/network.c @@ -121,10 +121,17 @@ pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool non_b } } + freeifaddrs(ifaddr); + + if (star_length == 0) + { + // cannot bind to anything! + return 1; + } + *fds = star_fds; *length = star_length; - freeifaddrs(ifaddr); return 0; }