]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
fix null pointer dereference issue in function ub_ctx_set_fwd of file libunbound... 1073/head
authorzhailiangliang <zhailiangliang@loongson.cn>
Tue, 21 May 2024 08:40:16 +0000 (08:40 +0000)
committerzhailiangliang <zhailiangliang@loongson.cn>
Tue, 21 May 2024 08:40:35 +0000 (08:40 +0000)
libunbound/libunbound.c

index 17057ec6c014e9edade6448b63ca65dec0a09e8b..3c895514950388efce672d043d59a4433ff3487c 100644 (file)
@@ -981,7 +981,8 @@ ub_ctx_set_fwd(struct ub_ctx* ctx, const char* addr)
        if(!addr) {
                /* disable fwd mode - the root stub should be first. */
                if(ctx->env->cfg->forwards &&
-                       strcmp(ctx->env->cfg->forwards->name, ".") == 0) {
+                       (ctx->env->cfg->forwards->name &&
+                       strcmp(ctx->env->cfg->forwards->name, ".") == 0)) {
                        s = ctx->env->cfg->forwards;
                        ctx->env->cfg->forwards = s->next;
                        s->next = NULL;
@@ -1001,7 +1002,8 @@ ub_ctx_set_fwd(struct ub_ctx* ctx, const char* addr)
        /* it parses, add root stub in front of list */
        lock_basic_lock(&ctx->cfglock);
        if(!ctx->env->cfg->forwards ||
-               strcmp(ctx->env->cfg->forwards->name, ".") != 0) {
+               (ctx->env->cfg->forwards->name &&
+               strcmp(ctx->env->cfg->forwards->name, ".") != 0)) {
                s = calloc(1, sizeof(*s));
                if(!s) {
                        lock_basic_unlock(&ctx->cfglock);
@@ -1019,6 +1021,7 @@ ub_ctx_set_fwd(struct ub_ctx* ctx, const char* addr)
                ctx->env->cfg->forwards = s;
        } else {
                log_assert(ctx->env->cfg->forwards);
+               log_assert(ctx->env->cfg->forwards->name);
                s = ctx->env->cfg->forwards;
        }
        dupl = strdup(addr);