From a316afecb28340ae3af54b76870d631a9288f026 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 04:47:32 +0200 Subject: [PATCH] fix: possible memory issues --- src/ui.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui.c b/src/ui.c index 6c57cd1..840154d 100644 --- a/src/ui.c +++ b/src/ui.c @@ -109,6 +109,7 @@ static char* fmt_time(const char* fmt) { } char* trunc_gethostname(const size_t MAXSIZE, const char* const ELLIPSIS) { + if(utf8len(ELLIPSIS) > MAXSIZE) return NULL; size_t alloc_size = MAXSIZE + 1; char* buf = malloc(alloc_size); if (!buf) return NULL; @@ -116,7 +117,7 @@ char* trunc_gethostname(const size_t MAXSIZE, const char* const ELLIPSIS) { if (gethostname(buf, alloc_size) == 0) return buf; if (errno == ENAMETOOLONG) { buf[alloc_size] = '\0'; - if (utf8len(buf) > MAXSIZE) { + if (utf8len(buf) > MAXSIZE - utf8len(ELLIPSIS)) { strcpy(&buf[MAXSIZE - utf8len(ELLIPSIS)], ELLIPSIS); return buf; }