From 88a40384111b3965b88686ccdfc4306361eb35df Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 25 Feb 2026 03:03:21 +0200 Subject: [PATCH] irc: use snprintf for nuh concatenation --- src/irc.cpp | 5 +++-- src/util.hpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/irc.cpp b/src/irc.cpp index 6aed8b6..ad26b36 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -1316,8 +1316,9 @@ static void updateNuh(Client *client) { const char *u = client->username ? client->username : "*"; const char *h = client->hostname; delete[] client->nuh; - client->nuh = new char[strlen(n) + strlen(u) + strlen(h) + 3]; - sprintf(client->nuh, "%s!%s@%s", n, u, h); + size_t len = strlen(n) + strlen(u) + strlen(h) + 3; + client->nuh = new char[len]; + snprintf(client->nuh, len, "%s!%s@%s", n, u, h); stringlower(client->nuh); } static bool is_nick_valid(std::string_view nickname) { diff --git a/src/util.hpp b/src/util.hpp index d0fee34..80bc681 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -20,6 +20,7 @@ void stringlower(char *s); #pragma GCC poison calloc #pragma GCC poison realloc #pragma GCC poison free +#pragma GCC poison sprintf #endif #define strcpy_lit(a, b) memcpy((a), (b), sizeof(b)) char *mystrdup(const char *s); -- 2.56.0