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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 utils/nfsdctl/nfsdctl.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

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
-- 
2.47.1





[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux