Correctly handle invalid IP addresses
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jan 2018 18:42:21 +0000 (18:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jan 2018 18:42:21 +0000 (18:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libloc.c
src/python/database.c

index 61f7c56..da21d6f 100644 (file)
@@ -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;
 }
index d41da47..89d5780 100644 (file)
@@ -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