]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
authzone: fix memory leak in xfer_set_masters() error path (#1480)
authorPetr Vaganov <petrvaganoff@gmail.com>
Fri, 24 Jul 2026 10:24:49 +0000 (17:24 +0700)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2026 10:24:49 +0000 (12:24 +0200)
Added memory deallocation for the `file` and `host` fields of the
`auth_master` node in the event of a URL/allocation error, and
unlinked the partially created node from the masters list by
resetting the link that pointed to it.

Signed-off-by: Petr Vaganov <petrvaganoff@gmail.com>
services/authzone.c

index 7c9ead951f7dc5bcc12b2f2d2acc3d5b5cc23a52..72b37fef9e79f21945f36c8a983e7b68a3c51bec 100644 (file)
@@ -7596,35 +7596,48 @@ xfer_set_masters(struct auth_master** list, struct config_auth* c,
 {
        struct auth_master* m;
        struct config_strlist* p;
+       struct auth_master** tail;
        /* list points to the first, or next pointer for the new element */
        while(*list) {
                list = &( (*list)->next );
        }
        if(with_http)
          for(p = c->urls; p; p = p->next) {
+               tail = list;
                m = auth_master_new(&list);
                if(!m) return 0;
                m->http = 1;
-               if(!parse_url(p->str, &m->host, &m->file, &m->port, &m->ssl))
+               if(!parse_url(p->str, &m->host, &m->file, &m->port, &m->ssl)) {
+                       free(m->host);
+                       free(m->file);
+                       free(m);
+                       *tail = NULL;
                        return 0;
+               }
        }
        for(p = c->masters; p; p = p->next) {
+               tail = list;
                m = auth_master_new(&list);
                if(!m) return 0;
                m->ixfr = 1; /* this flag is not configurable */
                m->host = strdup(p->str);
                if(!m->host) {
                        log_err("malloc failure");
+                       free(m);
+                       *tail = NULL;
                        return 0;
                }
        }
        for(p = c->allow_notify; p; p = p->next) {
+               tail = list;
                m = auth_master_new(&list);
                if(!m) return 0;
                m->allow_notify = 1;
                m->host = strdup(p->str);
                if(!m->host) {
                        log_err("malloc failure");
+                       free(m);
+                       *tail = NULL;
                        return 0;
                }
        }