0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 15:30:52 +01:00

webirc: Check validity of given IP.

This commit is contained in:
Jilles Tjoelker 2014-02-23 21:14:09 +01:00
parent a5de4edefd
commit 0391874cc7

View file

@ -77,8 +77,11 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
{ {
struct ConfItem *aconf; struct ConfItem *aconf;
const char *encr; 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"); sendto_one(source_p, "NOTICE * :Invalid IP");
return 0; return 0;
@ -116,15 +119,28 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
return 0; 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) if(strlen(parv[3]) <= HOSTLEN)
rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host)); rb_strlcpy(source_p->host, parv[3], sizeof(source_p->host));
else else
rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); 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 */ /* Check dlines now, klines will be checked on registration */
if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip,