From 0391874cc7b9ba88409f0c2b0728196b5262aa36 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 23 Feb 2014 21:14:09 +0100 Subject: [PATCH] webirc: Check validity of given IP. --- extensions/m_webirc.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/extensions/m_webirc.c b/extensions/m_webirc.c index ea6bc362..5760a168 100644 --- a/extensions/m_webirc.c +++ b/extensions/m_webirc.c @@ -77,8 +77,11 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char { struct ConfItem *aconf; const char *encr; + struct rb_sockaddr_storage addr; - if (!strchr(parv[4], '.') && !strchr(parv[4], ':')) + if ((!strchr(parv[4], '.') && !strchr(parv[4], ':')) || + strlen(parv[4]) + (*parv[4] == ':') >= + sizeof(source_p->sockhost)) { sendto_one(source_p, "NOTICE * :Invalid IP"); return 0; @@ -116,15 +119,28 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char return 0; } + if (rb_inet_pton_sock(parv[4], (struct sockaddr *)&addr) <= 0) + { + sendto_one(source_p, "NOTICE * :Invalid IP"); + return 0; + } - rb_strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost)); + if (*parv[4] == ':') + { + source_p->sockhost[0] = '0'; + rb_strlcpy(source_p->sockhost + 1, parv[4], + sizeof(source_p->sockhost) - 1); + } + else + rb_strlcpy(source_p->sockhost, parv[4], + sizeof(source_p->sockhost)); if(strlen(parv[3]) <= HOSTLEN) rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host)); else rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); - - rb_inet_pton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip); + + source_p->localClient->ip = addr; /* Check dlines now, klines will be checked on registration */ if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip,