Skip to content

Commit

Permalink
- irc.c:m_privmsg(): sanitize nickname parsing logic; don't run every…
Browse files Browse the repository at this point in the history
… privmsg through strcspn() when we can stop parsing parv[3] earlier

git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/trunk@8126 82007160-df01-0410-b94d-b575c5fd34c7
  • Loading branch information
michael committed Apr 3, 2017
1 parent 6edea82 commit 1ecde47
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/irc.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ static void
m_privmsg(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
const struct ChannelConf *channel = NULL;
size_t nick_len;

if (source_p == NULL)
return;
Expand All @@ -247,19 +246,18 @@ m_privmsg(char *parv[], unsigned int parc, const char *msg, const char *source_p
if ((channel = get_channel(parv[2])) == NULL)
return;

/* Find a suitable length to compare with */
nick_len = strcspn(parv[3], " :,");
int hit = strncasecmp(parv[3], "!all ", 5) == 0;
if (hit == 0)
{
size_t nick_len = strlen(IRCItem->nick);

if (nick_len < 3 && strlen(IRCItem->nick) >= 3)
nick_len = 3;
if (strncasecmp(parv[3], IRCItem->nick, nick_len) == 0)
hit = *(parv[3] + nick_len) == ' ';
}

/* Message is a command */
if (strncasecmp(parv[3], IRCItem->nick, nick_len) == 0 ||
strncasecmp(parv[3], "!all", 4) == 0)
{
if (hit)
/* XXX command_parse will alter parv[3]. */
command_parse(parv[3], channel, source_p);
}
}

/* m_notice
Expand Down

0 comments on commit 1ecde47

Please sign in to comment.