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/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 diff --git a/libratbox/include/rb_tools.h b/libratbox/include/rb_tools.h index b812ae86..f77bfa31 100644 --- a/libratbox/include/rb_tools.h +++ b/libratbox/include/rb_tools.h @@ -92,16 +92,29 @@ 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 - ret = malloc(y); + size_t len = rb_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)) 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); 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); 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; }