summaryrefslogtreecommitdiffstats
path: root/main/gdnsd/0001-Fix-ztree_txn_-API-to-work.patch
blob: f607d08c52d29e4ff4c6adfcfb2bca01bc0ba5c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
From e4d663a531205cdb281318bc912d76f2be22b328 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Thu, 11 Jul 2013 18:47:22 +0300
Subject: [PATCH 1/2] Fix ztree_txn_* API to work

ztree_clone() sets ztclone->zones to valid pointer even where
it was NULL in the original ztree. This happens since malloc(0)
returns always valid pointer. This confuses _ztree_update() and
various other places as in several cases ->zones is tested
instead of ->zones_len.

Fix ztree_clone() to keep ->zones as NULL if the original had
it as NULL.
---
 gdnsd/ztree.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gdnsd/ztree.c b/gdnsd/ztree.c
index 57ff6d6..3924504 100644
--- a/gdnsd/ztree.c
+++ b/gdnsd/ztree.c
@@ -526,9 +526,14 @@ static ztree_t* ztree_clone(const ztree_t* original) {
 
     ztree_t* ztclone = malloc(sizeof(ztree_t));
     ztclone->label = original->label;
-    ztclone->zones = malloc(original->zones_len * sizeof(zone_t*));
-    memcpy(ztclone->zones, original->zones, original->zones_len * sizeof(zone_t*));
-    ztclone->zones_len = original->zones_len;
+    if  (original->zones) {
+        ztclone->zones = malloc(original->zones_len * sizeof(zone_t*));
+        memcpy(ztclone->zones, original->zones, original->zones_len * sizeof(zone_t*));
+        ztclone->zones_len = original->zones_len;
+    } else {
+        ztclone->zones = NULL;
+        ztclone->zones_len = 0;
+    }
     ztchildren_t* old_ztc = original->children;
     if(old_ztc) {
         ztchildren_t* new_ztc = ztclone->children = calloc(1, sizeof(ztchildren_t));
-- 
1.8.3.2