mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-16 07:56:12 +03:00
Fixed IPv4+Port address parsing
This commit is contained in:
parent
b1ee051cee
commit
b83c1109ad
@ -88,6 +88,10 @@ class REQUEST_STORED_CONTEXT : public IHttpStoredContext
|
|||||||
|
|
||||||
char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
|
char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
|
||||||
{
|
{
|
||||||
|
const char *format = "%15[0-9.]:%5[0-9]";
|
||||||
|
char ip[16] = { 0 }; // ip4 addresses have max len 15
|
||||||
|
char port[6] = { 0 }; // port numbers are 16bit, ie 5 digits max
|
||||||
|
|
||||||
DWORD len = 50;
|
DWORD len = 50;
|
||||||
char *buf = (char *)apr_palloc(pool, len);
|
char *buf = (char *)apr_palloc(pool, len);
|
||||||
|
|
||||||
@ -98,6 +102,14 @@ char *GetIpAddr(apr_pool_t *pool, PSOCKADDR pAddr)
|
|||||||
|
|
||||||
WSAAddressToString(pAddr, sizeof(SOCKADDR), NULL, buf, &len);
|
WSAAddressToString(pAddr, sizeof(SOCKADDR), NULL, buf, &len);
|
||||||
|
|
||||||
|
// test for IPV4 with port on the end
|
||||||
|
if (sscanf(buf, format, ip, port) == 2) {
|
||||||
|
// IPV4 but with port - remove the port
|
||||||
|
char* input = ":";
|
||||||
|
char* ipv4 = strtok(buf, input);
|
||||||
|
return ipv4;
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user