diff mbox series

[4/4] nfs-utils: nfsdctl: fix host-limited add listener

Message ID 20250205154333.58646-5-okorniev@redhat.com (mailing list archive)
State New
Headers show
Series nfs-utils: nfsdctl fixups | expand

Commit Message

Olga Kornievskaia Feb. 5, 2025, 3:43 p.m. UTC
If in nfs.conf there was "host=<hostname>" configuration that
limited knfsd to listen on a particular hostname, then
add_listener() had to fit <type>:<hostname>:<port> into
144bytes to create a listener or be truncated which leads
to failure of said listener creation.

Instead allocate needed memory dynamically to allow for
long hostname values.

Signed-off-by: Olga Kornievskaia <okorniev@redhat.com>
---
 utils/nfsdctl/nfsdctl.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/utils/nfsdctl/nfsdctl.c b/utils/nfsdctl/nfsdctl.c
index 64ce44a1..05fecc71 100644
--- a/utils/nfsdctl/nfsdctl.c
+++ b/utils/nfsdctl/nfsdctl.c
@@ -1283,21 +1283,26 @@  static int pool_mode_func(struct nl_sock *sock, int argc, char **argv)
 	return pool_mode_doit(sock, cmd, pool_mode);
 }
 
-#define MAX_LISTENER_LEN (64 * 2 + 16)
-
 static int
 add_listener(const char *netid, const char *addr, const char *port)
 {
-		char buf[MAX_LISTENER_LEN];
+		char *buf;
+		int ret;
+		int size = strlen(addr) + 1 + 16;
 
+		buf = calloc(size, sizeof(int));
+		if (!buf)
+			return -ENOMEM;
 		if (strchr(addr, ':'))
-			snprintf(buf, MAX_LISTENER_LEN, "+%s:[%s]:%s",
+			snprintf(buf, size, "+%s:[%s]:%s",
 				 netid, addr, port);
 		else
-			snprintf(buf, MAX_LISTENER_LEN, "+%s:%s:%s",
+			snprintf(buf, size, "+%s:%s:%s",
 				 netid, addr, port);
-		buf[MAX_LISTENER_LEN - 1] = '\0';
-		return update_listeners(buf);
+		buf[size - 1] = '\0';
+		ret = update_listeners(buf);
+		free(buf);
+		return ret;
 }
 
 static void