telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit 0b6c6d1ad37c7c17e6c0095dc74486759cdc8336
parent c0b8d26ae6c51a2e39b642c18018a34849f26bab
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 11 Oct 2018 22:26:21 +0200

Check for invalid IP addresses

Diffstat:
Msrc/location.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/location.c b/src/location.c @@ -62,6 +62,9 @@ location(struct http_request *req) time_t rawtime; struct tm *info; + struct sockaddr_in ipv4; + struct sockaddr_in6 ipv6; + http_populate_get(req); struct kore_buf json; @@ -90,6 +93,13 @@ location(struct http_request *req) ip = custom_ip; } + // Check for invalid IP addresses + if (!inet_pton(AF_INET, ip, &(ipv4.sin_addr)) && + !inet_pton(AF_INET6, ip, &(ipv6.sin6_addr))) { + answer = "{\"code\": 401, \"message\": \"Input string is not a valid IP address\"}"; + http_response(req, 400, answer, strlen(answer)); + } + if (http_argument_get_string(req, "callback", &callback)) { kore_buf_appendf(&json, "%s(", callback); is_callback = true;