From 26d491b95fce9be22a72f498907dcaccbcb20b15 Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Sun, 27 Mar 2016 17:28:26 -0500 Subject: [PATCH] authd: pass in uint32_t rid's. --- authd/authd.c | 9 ++++++++- authd/authd.h | 2 +- authd/dns.c | 16 +++++++--------- authd/dns.h | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/authd/authd.c b/authd/authd.c index 6f500a9d..8aabf267 100644 --- a/authd/authd.c +++ b/authd/authd.c @@ -53,6 +53,7 @@ static void handle_stat(int parc, char *parv[]) { authd_stat_handler handler; + long lrid; if(parc < 3) { @@ -60,10 +61,16 @@ handle_stat(int parc, char *parv[]) return; } + if((lrid = strtol(parv[1], NULL, 16)) > UINT32_MAX) + { + warn_opers(L_CRIT, "BUG: handle_stat got a rid that was too large: %lx", lrid); + return; + } + if (!(handler = authd_stat_handlers[(unsigned char)parv[2][0]])) return; - handler(parv[1], parv[2][0]); + handler((uint32_t)lrid, parv[2][0]); } static void diff --git a/authd/authd.h b/authd/authd.h index 07c746ca..43901dc0 100644 --- a/authd/authd.h +++ b/authd/authd.h @@ -40,7 +40,7 @@ struct auth_opts_handler extern rb_helper *authd_helper; typedef void (*authd_cmd_handler)(int parc, char *parv[]); -typedef void (*authd_stat_handler)(const char *rid, const char letter); +typedef void (*authd_stat_handler)(uint32_t rid, const char letter); typedef void (*authd_reload_handler)(const char letter); extern authd_cmd_handler authd_cmd_handlers[256]; diff --git a/authd/dns.c b/authd/dns.c index 487979fe..7d6d9472 100644 --- a/authd/dns.c +++ b/authd/dns.c @@ -252,17 +252,15 @@ handle_resolve_dns(int parc, char *parv[]) } void -enumerate_nameservers(const char *rid, const char letter) +enumerate_nameservers(uint32_t rid, const char letter) { char buf[(HOSTIPLEN + 1) * IRCD_MAXNS]; - char *c = buf; size_t s = 0; - uint32_t i_rid = (uint32_t)strtol(rid, NULL, 16); if (!irc_nscount) { /* Shouldn't happen */ - stats_error(i_rid, letter, "NONAMESERVERS"); + stats_error(rid, letter, "NONAMESERVERS"); return; } @@ -276,19 +274,19 @@ enumerate_nameservers(const char *rid, const char letter) if (!addr[0]) { /* Shouldn't happen */ - stats_error(i_rid, letter, "INVALIDNAMESERVER"); + stats_error(rid, letter, "INVALIDNAMESERVER"); return; } addrlen = strlen(addr) + 1; - (void)snprintf(c, sizeof(buf) - s, "%s ", addr); - c += addrlen; + (void)snprintf(&buf[s], sizeof(buf) - s, "%s ", addr); s += addrlen; } - *(--c) = '\0'; + if(s > 0) + buf[--s] = '\0'; - stats_result(i_rid, letter, "%s", buf); + stats_result(rid, letter, "%s", buf); } void diff --git a/authd/dns.h b/authd/dns.h index b4eae8c6..7383ab69 100644 --- a/authd/dns.h +++ b/authd/dns.h @@ -55,7 +55,7 @@ extern struct dns_query *lookup_ip(const char *host, int aftype, DNSCB callback, extern void cancel_query(struct dns_query *query); extern void handle_resolve_dns(int parc, char *parv[]); -extern void enumerate_nameservers(const char *rid, const char letter); +extern void enumerate_nameservers(uint32_t rid, const char letter); extern void reload_nameservers(const char letter); #endif