]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
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 61f7c5600787dd2e9ff29e97cb0f91a11fa97cb2..da21d6fc4d03ccff4988f25ad902bae1ea322bf8 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);
        }
 
        DEBUG(ctx, "%s is not an valid IP address\n", string);
-       return 1;
+       return -EINVAL;
 }
 }
index d41da47e52813c23ecbb94da3d27bae998f3c6d6..89d578022db7dd4974904afc497515cbf271a1a9 100644 (file)
@@ -138,6 +138,11 @@ static PyObject* Database_lookup(DatabaseObject* self, PyObject* args) {
        // Nothing found
        } else if (r == 1) {
                Py_RETURN_NONE;
        // 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
        }
 
        // Unexpected error