[Tarantool-patches] [PATCH 14/16] sio: increase SERVICE_NAME_MAXLEN size
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sat Mar 20 03:42:36 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
---
src/lib/core/sio.c | 2 +-
src/lib/core/sio.h | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/lib/core/sio.c b/src/lib/core/sio.c
index deffee86c..25c34ea59 100644
--- a/src/lib/core/sio.c
+++ b/src/lib/core/sio.c
@@ -78,7 +78,7 @@ sio_socketname(int fd)
{
/* Preserve errno */
int save_errno = errno;
- int name_size = 2 * SERVICE_NAME_MAXLEN;
+ int name_size = SERVICE_NAME_MAXLEN;
char *name = static_alloc(name_size);
int rc = sio_socketname_to_buffer(fd, name, name_size);
/*
diff --git a/src/lib/core/sio.h b/src/lib/core/sio.h
index db2e3281f..4f5a7f6f3 100644
--- a/src/lib/core/sio.h
+++ b/src/lib/core/sio.h
@@ -52,7 +52,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,
+};
/**
* Check if an errno, returned from a sio function, means a
--
2.24.3 (Apple Git-128)
More information about the Tarantool-patches
mailing list