From 927e82f2922107301794b8fbbf3a3fa262dd78b6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 8 Jan 2018 18:42:21 +0000 Subject: [PATCH] Correctly handle invalid IP addresses Signed-off-by: Michael Tremer --- src/libloc.c | 2 +- src/python/database.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libloc.c b/src/libloc.c index 61f7c56..da21d6f 100644 --- a/src/libloc.c +++ b/src/libloc.c @@ -158,5 +158,5 @@ LOC_EXPORT int loc_parse_address(struct loc_ctx* ctx, const char* string, struct } DEBUG(ctx, "%s is not an valid IP address\n", string); - return 1; + return -EINVAL; } diff --git a/src/python/database.c b/src/python/database.c index d41da47..89d5780 100644 --- a/src/python/database.c +++ b/src/python/database.c @@ -138,6 +138,11 @@ static PyObject* Database_lookup(DatabaseObject* self, PyObject* args) { // Nothing found } else if (r == 1) { Py_RETURN_NONE; + + // Invalid input + } else if (r == -EINVAL) { + PyErr_Format(PyExc_ValueError, "Invalid IP address: %s", address); + return NULL; } // Unexpected error -- 2.39.2