From a32710f41d519d971c08ddc6e2a8d643dc5d4af6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Thu, 26 Jan 2017 15:10:03 +0100 Subject: [PATCH] hints: more NULL checks Calling `hints.del()` would cause a crash. It wasn't apparent to me that NULL could be passed through. --- modules/hints/hints.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/hints/hints.c b/modules/hints/hints.c index b79ad5942..ff6e1f8ad 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -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); -- 2.47.2