[PATCH] Fix possible SIGSEGV on too many ftrigr listeners

From: Carlos Eduardo <carana2099_at_gmail.com>
Date: Sun, 5 May 2024 13:28:20 -0300

If a single s6-ftrigrd is requested to listen on many listeners, the
genalloc_readyplus may have to move the ftrigio's to a new memory area,
causing the char* inside their buffer to get outdated, overwriting
unrelated memory areas when filling the buffers and possibly triggering
a SIGSEGV.

With this patch, it always updates the buffer's char* before filling it.

Signed-off-by: Carlos Eduardo <carana2099_at_gmail.com>
---
 src/libs6/s6-ftrigrd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libs6/s6-ftrigrd.c b/src/libs6/s6-ftrigrd.c
index b6ca40b..e3366cc 100644
--- a/src/libs6/s6-ftrigrd.c
+++ b/src/libs6/s6-ftrigrd.c
_at__at_ -90,13 +90,13 _at__at_ static void remove (size_t i)
   ftrigio *a = genalloc_s(ftrigio, &g) ;
   ftrigio_deepfree(a + i) ;
   a[i] = a[--n] ;
-  a[i].b.c.x = a[i].buf ;
   genalloc_setlen(ftrigio, &g, n) ;
 }
 
 static inline int ftrigio_read (ftrigio *p)
 {
   unsigned int i = FTRIGRD_MAXREADS ;
+  p->b.c.x = p->buf ;
   while (i--)
   {
     regmatch_t pmatch ;
-- 
2.44.0
Received on Sun May 05 2024 - 18:28:20 CEST

This archive was generated by hypermail 2.4.0 : Sun May 05 2024 - 18:29:20 CEST