From 162fd708ae1e18553e624e095abf9b4595a0d155 Mon Sep 17 00:00:00 2001 From: Thomas Mannfred Carlsson Date: Fri, 6 Feb 2026 00:33:58 +0200 Subject: [PATCH 1/6] Fix receive/send mixup in stats ? output --- modules/m_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/m_stats.c b/modules/m_stats.c index 06e4a04f..b8d79061 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -1439,7 +1439,7 @@ stats_servlinks(struct Client *source_p) "? :Sent total : %7.2f %s", _GMKv((sent / 1024)), _GMKs((sent / 1024))); sendto_one_numeric(source_p, RPL_STATSDEBUG, - "? :Recv total : %7.2f %s", _GMKv((sent / 1024)), _GMKs((receive / 1024))); + "? :Recv total : %7.2f %s", _GMKv((receive / 1024)), _GMKs((receive / 1024))); uptime = (rb_current_time() - startup_time); From 7eb5141a32d5838e89744956cc4301c6796ba006 Mon Sep 17 00:00:00 2001 From: Aaron Sethman Date: Fri, 6 Feb 2026 02:53:43 -0500 Subject: [PATCH 2/6] fix replacement strndup --- libratbox/include/rb_tools.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libratbox/include/rb_tools.h b/libratbox/include/rb_tools.h index b812ae86..bd479171 100644 --- a/libratbox/include/rb_tools.h +++ b/libratbox/include/rb_tools.h @@ -97,11 +97,12 @@ rb_strndup(const char *x, size_t y) { char *ret; #ifndef RB_HAVE_STRNDUP - ret = malloc(y); + size_t len = strnlen(x, y); + ret = malloc(len + 1); if(rb_unlikely(ret == NULL)) rb_outofmemory(); - rb_strlcpy(ret, x, y); - return (ret); + ret[len] = '\0'; + return memcpy(x, y, len); #else ret = strndup(x, y); if(rb_unlikely(ret == NULL)) From 1277d6bb52fde7f1c7403a1617db5ef7defa7595 Mon Sep 17 00:00:00 2001 From: Aaron Sethman Date: Fri, 6 Feb 2026 03:00:38 -0500 Subject: [PATCH 3/6] no need for the + 1 when using strndup to allocate the topic --- src/channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/channel.c b/src/channel.c index aba9362d..b7a3fdc1 100644 --- a/src/channel.c +++ b/src/channel.c @@ -788,7 +788,7 @@ set_channel_topic(struct Channel *chptr, const char *topic, const char *topic_in else rb_free(chptr->topic->topic); - chptr->topic->topic = rb_strndup(topic, ConfigChannel.topiclen + 1); /* the + 1 for the \0 */ + chptr->topic->topic = rb_strndup(topic, ConfigChannel.topiclen); rb_strlcpy(chptr->topic->topic_info, topic_info, sizeof(chptr->topic->topic_info)); chptr->topic->topic_time = topicts; } From b4f00a115e14639ffb7b4cd7f52b89132900f994 Mon Sep 17 00:00:00 2001 From: Aaron Sethman Date: Fri, 6 Feb 2026 04:36:13 -0500 Subject: [PATCH 4/6] In theory something doesn't have strnlen, provide one if necessary. --- libratbox/configure | 5 ++++- libratbox/configure.ac | 5 ++++- libratbox/include/rb_tools.h | 14 +++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libratbox/configure b/libratbox/configure index af7c22e4..dc5b4e20 100755 --- a/libratbox/configure +++ b/libratbox/configure @@ -16667,6 +16667,7 @@ fi rb_have_strndup=$ac_cv_func_strndup rb_have_strlcat=$ac_cv_func_strlcat rb_have_strlcpy=$ac_cv_func_strlcpy + rb_have_strnlen=$ac_cv_func_strnlen rb_sizeof_time_t=$ac_cv_sizeof_time_t rb_sizeof_long=$ac_cv_sizeof_long @@ -18033,7 +18034,9 @@ fi if test "x$rb_have_strlcat" = "xyes"; then echo "#define RB_HAVE_STRLCAT 1" >> $outfile fi - +if test "x$rb_have_strnlen" = "xyes"; then + echo "#define RB_HAVE_STRNLEN 1" >> $outfile +fi if test "x$rb_have_ipv6" = "xyes"; then echo "#define RB_IPV6 1" >> $outfile diff --git a/libratbox/configure.ac b/libratbox/configure.ac index 11c52e90..1a48fa02 100644 --- a/libratbox/configure.ac +++ b/libratbox/configure.ac @@ -540,7 +540,9 @@ fi if test "x$rb_have_strlcat" = "xyes"; then echo "#define RB_HAVE_STRLCAT 1" >> $outfile fi - +if test "x$rb_have_strnlen" = "xyes"; then + echo "#define RB_HAVE_STRNLEN 1" >> $outfile +fi if test "x$rb_have_ipv6" = "xyes"; then echo "#define RB_IPV6 1" >> $outfile @@ -646,6 +648,7 @@ fi rb_have_strndup=$ac_cv_func_strndup rb_have_strlcat=$ac_cv_func_strlcat rb_have_strlcpy=$ac_cv_func_strlcpy + rb_have_strnlen=$ac_cv_func_strnlen rb_sizeof_time_t=$ac_cv_sizeof_time_t rb_sizeof_long=$ac_cv_sizeof_long diff --git a/libratbox/include/rb_tools.h b/libratbox/include/rb_tools.h index bd479171..f77bfa31 100644 --- a/libratbox/include/rb_tools.h +++ b/libratbox/include/rb_tools.h @@ -92,12 +92,24 @@ rb_realloc(void *x, size_t y) return (ret); } +#ifndef RB_HAVE_STRNLEN +size_t static +rb_strnlen(const char *s, size_t n) +{ + size_t p; + for (p = 0; p < n && s[p]; p++) {} + return p; +} +#else +#define rb_strnlen(x) strnlen(x) +#endif + static inline char * rb_strndup(const char *x, size_t y) { char *ret; #ifndef RB_HAVE_STRNDUP - size_t len = strnlen(x, y); + size_t len = rb_strnlen(x, y); ret = malloc(len + 1); if(rb_unlikely(ret == NULL)) rb_outofmemory(); From 8ac2a6c779686f3f74fcb07dc306e798440f7eb7 Mon Sep 17 00:00:00 2001 From: Aaron Sethman Date: Fri, 6 Feb 2026 04:37:03 -0500 Subject: [PATCH 5/6] use quotes instead of angle brackets for rb includes --- libratbox/include/ratbox_lib.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libratbox/include/ratbox_lib.h b/libratbox/include/ratbox_lib.h index 34d33226..1d1177dd 100644 --- a/libratbox/include/ratbox_lib.h +++ b/libratbox/include/ratbox_lib.h @@ -203,13 +203,13 @@ extern const char *libratbox_infotext[]; #endif -#include -#include -#include -#include -#include -#include -#include -#include +#include "rb_tools.h" +#include "rb_commio.h" +#include "rb_linebuf.h" +#include "rb_snprintf.h" +#include "rb_event.h" +#include "rb_helper.h" +#include "rb_rawbuf.h" +#include "rb_patricia.h" #endif From 712635b7b12565df2a6e0ba0b4ff19f0ba6c07d2 Mon Sep 17 00:00:00 2001 From: Aaron Sethman Date: Fri, 6 Feb 2026 05:51:37 -0500 Subject: [PATCH 6/6] Remove old logic that truncated nicks with a ~ in them instead of just rejecting them outright. --- modules/core/m_nick.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index 7e7bce0f..8eeb35c9 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -123,21 +123,13 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char * { struct Client *target_p; char nick[NICKLEN]; - char *s; - if(parc < 2 || EmptyString(parv[1]) || (parv[1][0] == '~')) + if(parc < 2 || EmptyString(parv[1])) { sendto_one_numeric(source_p, s_RPL(ERR_NONICKNAMEGIVEN)); return 0; } - /* due to the scandinavian origins, (~ being uppercase of ^) and ~ - * being disallowed as a nick char, we need to chop the first ~ - * instead of just erroring. - */ - if((s = strchr(parv[1], '~'))) - *s = '\0'; - /* copy the nick and terminate it */ rb_strlcpy(nick, parv[1], ServerInfo.nicklen); @@ -180,21 +172,13 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p { struct Client *target_p; char nick[NICKLEN]; - char *s; - if(parc < 2 || EmptyString(parv[1]) || (parv[1][0] == '~')) + if(parc < 2 || EmptyString(parv[1])) { sendto_one_numeric(source_p, s_RPL(ERR_NONICKNAMEGIVEN)); return 0; } - /* due to the scandinavian origins, (~ being uppercase of ^) and ~ - * being disallowed as a nick char, we need to chop the first ~ - * instead of just erroring. - */ - if((s = strchr(parv[1], '~'))) - *s = '\0'; - /* mark end of grace period, to prevent nickflooding */ if(!IsFloodDone(source_p)) flood_endgrace(source_p);