mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 15:01:03 +08:00
Fix 1452 - byte order issue in mg_check_ip_acl
This commit is contained in:
parent
1a8e3c2e31
commit
59c4dfa33b
@ -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 == '+';
|
||||
}
|
||||
|
@ -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 == '+';
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user