[Tarantool-patches] [PATCH 13/15] sio: increase SERVICE_NAME_MAXLEN size

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Thu Mar 25 00:24:25 MSK 2021


It was 32, and couldn't fit long IPv6 and Unix socket addresses.

The patch makes it 200 so now it fits any supported addresses
family used in the code.

Having SERVICE_NAME_MAXLEN valid is necessary to be able to save
a complete address string on the stack in the places where the
static buffer returned by sio_strfaddr() can't be used safely. For
instance, in the code working with Lua due to Lua GC which might
be invoked any moment and in a __gc handler could overwrite the
static buffer.

Needed for #5632

(cherry picked from commit 6b331f7a78aa409ad68ffc8ceb3deb3733a32473)
---
 src/sio.cc |  2 +-
 src/sio.h  | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/sio.cc b/src/sio.cc
index 0ba19346c..a425b8383 100644
--- a/src/sio.cc
+++ b/src/sio.cc
@@ -81,7 +81,7 @@ sio_socketname(int fd)
 {
 	/* Preserve errno */
 	int save_errno = errno;
-	static __thread char name[2 * SERVICE_NAME_MAXLEN];
+	static __thread char name[SERVICE_NAME_MAXLEN];
 	int rc = sio_socketname_to_buffer(fd, name, sizeof(name));
 	/*
 	 * Could fail only because of a bad format in snprintf, but it is not
diff --git a/src/sio.h b/src/sio.h
index f728af547..3b91f7eee 100644
--- a/src/sio.h
+++ b/src/sio.h
@@ -46,7 +46,16 @@
 extern "C" {
 #endif /* defined(__cplusplus) */
 
-enum { SERVICE_NAME_MAXLEN = 32 };
+enum {
+	/**
+	 * - Unix socket path is 108 bytes max;
+	 * - IP(v4, v6) max string len is 45;
+	 *
+	 * Max result is rounded up just in case the numbers are a bit different
+	 * on various platforms.
+	 */
+	SERVICE_NAME_MAXLEN = 200,
+};
 
 const char *
 sio_strfaddr(struct sockaddr *addr, socklen_t addrlen);
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list