Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] core: fix static_alloc buffer overflow
@ 2020-10-23 15:13 Sergey Ostanevich
  2020-10-23 20:06 ` Vladislav Shpilevoy
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Sergey Ostanevich @ 2020-10-23 15:13 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Vladislav Shpilevoy

Static buffer overflow in thread local pool causes random fails on OSX
platform. This was caused by an incorrect use of the allocator result:
the snprintf returns the full size of the formatted string, rather the
number of bytes written.

Fixes #5312

Branch: https://github.com/tarantool/tarantool/tree/sergos/gh-5312-crash-in-libeio
Issue: https://github.com/tarantool/tarantool/issues/5312

---
src/lib/core/sio.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/lib/core/sio.c b/src/lib/core/sio.c
index 97a512eee..44f952c7c 100644
--- a/src/lib/core/sio.c
+++ b/src/lib/core/sio.c
@@ -53,15 +53,15 @@ sio_socketname(int fd)
      int save_errno = errno;
      int name_size = 2 * SERVICE_NAME_MAXLEN;
      char *name = static_alloc(name_size);
-       int n = snprintf(name, name_size, "fd %d", fd);
+       int n = MIN(snprintf(name, name_size, "fd %d", fd), name_size);
      if (fd >= 0) {
              struct sockaddr_storage addr;
              socklen_t addrlen = sizeof(addr);
              int rc = getsockname(fd, (struct sockaddr *) &addr, &addrlen);
              if (rc == 0) {
-                       n += snprintf(name + n, name_size - n, ", aka %s",
+                       n += MIN(snprintf(name + n, name_size - n, ", aka %s",
                              sio_strfaddr((struct sockaddr *)&addr,
-                                                               addrlen));
+                                                addrlen)), name_size - n);
              }
              addrlen = sizeof(addr);
              rc = getpeername(fd, (struct sockaddr *) &addr, &addrlen);
-- 
2.24.3 (Apple Git-128)

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-11-03 22:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 15:13 [Tarantool-patches] [PATCH] core: fix static_alloc buffer overflow Sergey Ostanevich
2020-10-23 20:06 ` Vladislav Shpilevoy
2020-10-29 22:56 ` Vladislav Shpilevoy
2020-10-30  7:07   ` Cyrill Gorcunov
2020-10-31 16:33 ` Vladislav Shpilevoy
2020-11-02 13:19   ` Sergey Ostanevich
2020-11-02 21:09     ` Vladislav Shpilevoy
2020-11-02 21:18       ` Cyrill Gorcunov
2020-11-02 21:43         ` Vladislav Shpilevoy
2020-11-02 21:47           ` Cyrill Gorcunov
2020-11-03 13:59             ` Sergey Ostanevich
2020-11-03 14:08               ` Cyrill Gorcunov
2020-11-03 22:59 ` Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox