Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libratbox/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libratbox/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions libratbox/include/ratbox_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ extern const char *libratbox_infotext[];
#endif


#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>
#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
19 changes: 16 additions & 3 deletions libratbox/include/rb_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 2 additions & 18 deletions modules/core/m_nick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion modules/m_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down