Fix 1452 - byte order issue in mg_check_ip_acl

This commit is contained in:
Sergey Lyubka 2022-01-21 12:24:58 +00:00
parent 1a8e3c2e31
commit 59c4dfa33b
3 changed files with 3 additions and 3 deletions

View File

@ -4630,7 +4630,7 @@ int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip) {
uint32_t net, mask;
if (k.ptr[0] != '+' && k.ptr[0] != '-') return -1;
if (parse_net(&k.ptr[1], &net, &mask) == 0) return -2;
if ((remote_ip & mask) == net) allowed = k.ptr[0];
if ((mg_ntohl(remote_ip) & mask) == net) allowed = k.ptr[0];
}
return allowed == '+';
}

View File

@ -238,7 +238,7 @@ int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip) {
uint32_t net, mask;
if (k.ptr[0] != '+' && k.ptr[0] != '-') return -1;
if (parse_net(&k.ptr[1], &net, &mask) == 0) return -2;
if ((remote_ip & mask) == net) allowed = k.ptr[0];
if ((mg_ntohl(remote_ip) & mask) == net) allowed = k.ptr[0];
}
return allowed == '+';
}

View File

@ -1539,7 +1539,7 @@ static void test_udp(void) {
}
static void test_check_ip_acl(void) {
uint32_t ip = 0x01020304;
uint32_t ip = mg_htonl(0x01020304);
ASSERT(mg_check_ip_acl(mg_str(NULL), ip) == 1);
ASSERT(mg_check_ip_acl(mg_str(""), ip) == 1);
ASSERT(mg_check_ip_acl(mg_str("invalid"), ip) == -1);