Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make vhost "looks like a CIDR" check more precise #920

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions libathemecore/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ verbose_wallops(const char *fmt, ...)
bool
check_vhost_validity(struct sourceinfo *si, const char *host)
{
const char *p;
const char *p, *p2;

/* Never ever allow @!?* as they have special meaning in all ircds */
/* Empty, space anywhere and colon at the start break the protocol */
Expand All @@ -1246,8 +1246,13 @@ check_vhost_validity(struct sourceinfo *si, const char *host)
command_fail(si, fault_badparams, _("The vhost provided is too long."));
return false;
}
p = strrchr(host, '/');
if (p != NULL && isdigit((unsigned char)p[1]))
p = p2 = strrchr(host, '/');
// walk the vhost until we hit either the end or a non-digit
while (p != NULL && isdigit((unsigned char)p[1]))
p++;
// if we found a /, and are now at the end of the vhost, that
// means we found no non-digits, so it looks too much like a CIDR
if (p2 != NULL && p[1] == '\0')
Copy link
Contributor

@dwfreed dwfreed Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need storing a second copy of the strrchr return value. If the return value was NULL then p will still be NULL here; if the return value was not NULL then p will never be NULL either.

{
command_fail(si, fault_badparams, _("The vhost provided looks like a CIDR mask."));
return false;
Expand Down