Skip to content
2 changes: 1 addition & 1 deletion include/s_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ void close_logfiles(void);
void
ilog(ilogfile dest, const char *fmt, ...) AFP(2, 3);
void report_operspy(struct Client *, const char *, const char *);
const char *smalldate(time_t);
const char *smalldate(time_t, char *, size_t);

#endif
17 changes: 17 additions & 0 deletions libratbox/include/rb_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ rb_dlinkDestroy(rb_dlink_node *node, rb_dlink_list *list)
rb_free(node);
}

static inline time_t
rb_parse_time(const char *s)
{
time_t t;
#if SIZEOF_LONG == SIZEOF_TIME_T
t = (time_t)atol(s);
#else
intmax_t v;
v = strtoimax(s, NULL, 10);
t = (time_t)v;
/* make overflow clamp to 0 */
if((intmax_t)t != v)
return 0;
#endif
return t;
}


typedef struct _rb_zstring
{
Expand Down
4 changes: 2 additions & 2 deletions modules/core/m_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *
if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
return 0;

newts = atol(parv[1]);
newts = rb_parse_time(parv[1]);
oldts = chptr->channelts;

/* making a channel TS0 */
Expand Down Expand Up @@ -504,7 +504,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
mode.key[0] = '\0';
mode.mode = mode.limit = 0;

newts = atol(parv[1]);
newts = rb_parse_time(parv[1]);

s = parv[3];
while(*s)
Expand Down
7 changes: 0 additions & 7 deletions modules/core/m_kick.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
int chasing = 0;
char *comment;
const char *name;
char *p = NULL;
const char *user;
static char buf[IRCD_BUFSIZE];

if(MyClient(source_p) && !IsFloodDone(source_p))
flood_endgrace(source_p);

*buf = '\0';
if((p = strchr(parv[1], ',')))
*p = '\0';

name = parv[1];

chptr = find_channel(name);
Expand Down Expand Up @@ -135,9 +131,6 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
*/
}

if((p = strchr(parv[2], ',')))
*p = '\0';

user = parv[2];

if(!(who = find_chasing(source_p, user, &chasing)))
Expand Down
4 changes: 2 additions & 2 deletions modules/core/m_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char
}

/* TS is higher, drop it. */
if(atol(parv[1]) > chptr->channelts)
if(rb_parse_time(parv[1]) > chptr->channelts)
return 0;

if(IsServer(source_p))
Expand Down Expand Up @@ -274,7 +274,7 @@ ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char
return 0;

/* TS is higher, drop it. */
if(atol(parv[1]) > chptr->channelts)
if(rb_parse_time(parv[1]) > chptr->channelts)
return 0;

switch (parv[3][0])
Expand Down
8 changes: 4 additions & 4 deletions modules/core/m_nick.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ mc_nick(struct Client *client_p, struct Client *source_p, int parc, const char *
return 0;
}

newts = atol(parv[2]);
newts = rb_parse_time(parv[2]);
target_p = find_client(parv[1]);

/* if the nick doesnt exist, allow it and process like normal */
Expand Down Expand Up @@ -370,7 +370,7 @@ ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char *
*/
}

newts = atol(parv[3]);
newts = rb_parse_time(parv[3]);

target_p = find_client(parv[1]);

Expand Down Expand Up @@ -415,7 +415,7 @@ ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *p
struct Client *target_p;
time_t newts = 0;

newts = atol(parv[3]);
newts = rb_parse_time(parv[3]);

if(parc != 10)
{
Expand Down Expand Up @@ -504,7 +504,7 @@ ms_save(struct Client *client_p, struct Client *source_p, int parc, const char *
sendto_realops_flags(UMODE_DEBUG, L_ALL,
"Ignored noop SAVE message for %s from %s",
target_p->name, source_p->name);
else if(target_p->tsinfo == atol(parv[2]))
else if(target_p->tsinfo == rb_parse_time(parv[2]))
save_user(client_p, source_p, target_p);
else
sendto_realops_flags(UMODE_SKILL, L_ALL,
Expand Down
4 changes: 2 additions & 2 deletions modules/m_dline.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,15 @@ set_dline(struct Client *source_p, const char *dlhost, const char *lreason, int
{
struct ConfItem *aconf;
char dlbuffer[IRCD_BUFSIZE];
const char *current_date;
char current_date[MAX_DATE_STRING];
const char *oper;
char *reason;
char *oper_reason;

reason = LOCAL_COPY_N(lreason, REASONLEN);

rb_set_time();
current_date = smalldate(rb_current_time());
smalldate(rb_current_time(), current_date, sizeof(current_date));

aconf = make_conf();
aconf->status = CONF_DLINE;
Expand Down
4 changes: 2 additions & 2 deletions modules/m_gline.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ set_local_gline(struct Client *source_p, const char *user, const char *host, con
{
char buffer[IRCD_BUFSIZE];
struct ConfItem *aconf;
const char *current_date;
char current_date[MAX_DATE_STRING];
char *my_reason;
char *oper_reason;

current_date = smalldate(rb_current_time());
smalldate(rb_current_time(), current_date, sizeof(current_date));

my_reason = LOCAL_COPY(reason);

Expand Down
4 changes: 2 additions & 2 deletions modules/m_kline.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ set_kline(struct Client *source_p, const char *user, const char *host, const cha
{
char buffer[IRCD_BUFSIZE];
struct ConfItem *aconf;
const char *current_date;
char current_date[MAX_DATE_STRING];
char *reason;
char *oper_reason;

Expand All @@ -342,7 +342,7 @@ set_kline(struct Client *source_p, const char *user, const char *host, const cha
return;

rb_set_time();
current_date = smalldate(rb_current_time());
smalldate(rb_current_time(), current_date, sizeof(current_date));
aconf = make_conf();
aconf->status = CONF_KILL;
aconf->user = rb_strdup(user);
Expand Down
8 changes: 2 additions & 6 deletions modules/m_knock.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,15 @@ static int
m_knock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
struct Channel *chptr;
char *p, *name;
const char *name;

if(MyClient(source_p) && ConfigChannel.use_knock == 0)
{
sendto_one_numeric(source_p, s_RPL(ERR_KNOCKDISABLED));
return 0;
}

name = LOCAL_COPY(parv[1]);

/* dont allow one knock to multiple chans */
if((p = strchr(name, ',')))
*p = '\0';
name = parv[1];

if(!IsChannelName(name))
{
Expand Down
13 changes: 4 additions & 9 deletions modules/m_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,19 @@ m_names(struct Client *client_p, struct Client *source_p, int parc, const char *
{
static time_t last_used = 0;
struct Channel *chptr = NULL;
char *s;

if(parc > 1 && !EmptyString(parv[1]))
{
char *p = LOCAL_COPY(parv[1]);
if((s = strchr(p, ',')))
*s = '\0';

if(!check_channel_name(p))
if(!check_channel_name(parv[1]))
{
sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), p);
sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]);
return 0;
}

if((chptr = find_channel(p)) != NULL)
if((chptr = find_channel(parv[1])) != NULL)
channel_member_names(chptr, source_p, 1);
else
sendto_one_numeric(source_p, s_RPL(RPL_ENDOFNAMES), p);
sendto_one_numeric(source_p, s_RPL(RPL_ENDOFNAMES), parv[1]);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions modules/m_services.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ me_rsfnc(struct Client *client_p, struct Client *source_p, int parc, const char
if(!clean_nick(parv[2]))
return 0;

curts = atol(parv[4]);
curts = rb_parse_time(parv[4]);

/* if tsinfo is different from what it was when services issued the
* RSFNC, then we ignore it. This can happen when a client changes
Expand Down Expand Up @@ -198,7 +198,7 @@ me_rsfnc(struct Client *client_p, struct Client *source_p, int parc, const char
exit_client(NULL, exist_p, &me, buf);
}

newts = atol(parv[3]);
newts = rb_parse_time(parv[3]);

/* timestamp is older than 15mins, ignore it */
if(newts < (rb_current_time() - 900))
Expand Down
2 changes: 1 addition & 1 deletion modules/m_svinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ms_svinfo(struct Client *client_p, struct Client *source_p, int parc, const char
* since we're here, might as well call rb_set_time() while we're at it
*/
rb_set_time();
theirtime = atol(parv[4]);
theirtime = rb_parse_time(parv[4]);
deltat = labs(theirtime - rb_current_time());

if(deltat > ConfigFileEntry.ts_max_delta)
Expand Down
2 changes: 1 addition & 1 deletion modules/m_tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *pa
if(chptr == NULL)
return 0;

newtopicts = atol(parv[2]);
newtopicts = rb_parse_time(parv[2]);

if(parc == 5)
{
Expand Down
3 changes: 0 additions & 3 deletions modules/m_topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *
struct membership *msptr;
char *p = NULL;

if((p = strchr(parv[1], ',')))
*p = '\0';

if(MyClient(source_p) && !IsFloodDone(source_p))
flood_endgrace(source_p);

Expand Down
7 changes: 2 additions & 5 deletions modules/m_whois.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,10 @@ static void
do_whois(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
struct Client *target_p;
char *nick;
char *p = NULL;
const char *nick;
int operspy = 0;

nick = LOCAL_COPY(parv[1]);
if((p = strchr(nick, ',')))
*p = '\0';
nick = parv[1];

if(IsOperSpy(source_p) && *nick == '!')
{
Expand Down
4 changes: 1 addition & 3 deletions modules/m_whowas.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ m_whowas(struct Client *client_p, struct Client *source_p, int parc, const char
return 0;
#endif

nick = LOCAL_COPY(parv[1]);
if((p = strchr(nick, ',')))
*p = '\0';
nick = parv[1];

whowas_list = whowas_get_list(nick);

Expand Down
9 changes: 8 additions & 1 deletion src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,14 @@ parse_dns_reply(rb_helper * helper)
while((len = rb_helper_read(helper, dnsBuf, sizeof(dnsBuf))) > 0)
{
parc = rb_string_to_array(dnsBuf, parv, MAXPARA+1);


if(parc == 0)
{
ilog(L_MAIN, "Resolver overdosed on crack...restarting resolver");
restart_resolver();
return;
}

if(*parv[0] == 'R')
{
if(parc != 5)
Expand Down
3 changes: 0 additions & 3 deletions src/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ fnv_hash(const unsigned char *s, unsigned int bits, size_t unused)
return h;
}

#if 1 /* unused currently */

static uint32_t
fnv_hash_len(const unsigned char *s, unsigned int bits, size_t len)
{
Expand All @@ -168,7 +166,6 @@ fnv_hash_len(const unsigned char *s, unsigned int bits, size_t len)
h = (h >> (32 - bits)) ^ (h & ((1U << bits) - 1));
return h;
}
#endif

static uint32_t
fnv_hash_upper_len(const unsigned char *s, unsigned int bits, size_t len)
Expand Down
13 changes: 9 additions & 4 deletions src/s_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,16 @@ ilog(ilogfile dest, const char *format, ...)
FILE *logfile = *log_table[dest].logfile;
char buf[IRCD_BUFSIZE];
char buf2[IRCD_BUFSIZE*2];
char current_date[MAX_DATE_STRING];
va_list args;

va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);

snprintf(buf2, sizeof(buf2), "%s %s\n", smalldate(rb_current_time()), buf);
smalldate(rb_current_time(), current_date, sizeof(current_date));

snprintf(buf2, sizeof(buf2), "%s %s\n", current_date, buf);
if(logfile == NULL || server_state_foreground)
{
fputs(buf2, stderr);
Expand Down Expand Up @@ -215,14 +218,16 @@ report_operspy(struct Client *source_p, const char *token, const char *arg)
}

const char *
smalldate(time_t ltime)
smalldate(time_t ltime, char *buf, size_t bufsz)
{
static char buf[MAX_DATE_STRING];
struct tm *lt;

if(buf == NULL)
return NULL;

lt = gmtime(&ltime);

snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
snprintf(buf, bufsz, "%d/%d/%d %02d.%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min);

return buf;
Expand Down
Loading