]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
hints: more NULL checks
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 26 Jan 2017 14:10:03 +0000 (15:10 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 26 Jan 2017 15:07:22 +0000 (16:07 +0100)
Calling `hints.del()` would cause a crash.
It wasn't apparent to me that NULL could be passed through.

modules/hints/hints.c

index b79ad59426906e5518f2bccf4202efd4d404ad9b..ff6e1f8adf753df2fc7692c9f26250691aed9de2 100644 (file)
@@ -338,6 +338,8 @@ static char* hint_set(void *env, struct kr_module *module, const char *args)
        if (!args)
                return NULL;
        auto_free char *args_copy = strdup(args);
+       if (!args_copy)
+               return NULL;
 
        int ret = -1;
        char *addr = strchr(args_copy, ' ');
@@ -355,7 +357,11 @@ static char* hint_set(void *env, struct kr_module *module, const char *args)
 static char* hint_del(void *env, struct kr_module *module, const char *args)
 {
        struct kr_zonecut *hints = module->data;
+       if (!args)
+               return NULL;
        auto_free char *args_copy = strdup(args);
+       if (!args_copy)
+               return NULL;
 
        int ret = -1;
        char *addr = strchr(args_copy, ' ');
@@ -476,7 +482,7 @@ static char* hint_root(void *env, struct kr_module *module, const char *args)
        struct kr_context *ctx = &engine->resolver;
        struct kr_zonecut *root_hints = &ctx->root_hints;
        /* Replace root hints if parameter is set */
-       if (args && strlen(args) > 0) {
+       if (args && args[0] != '\0') {
                JsonNode *root_node = json_decode(args);
                kr_zonecut_set(root_hints, (const uint8_t *)"");
                unpack_hint(root_hints, root_node, NULL);