[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r4172 - in trunk/OpenDNSSEC/signer/src: . adapter daemon parser scheduler signer tools util

Matthijs Mekking matthijs at nlnetlabs.nl
Mon Nov 8 15:25:53 CET 2010


Author: matthijs
Date: 2010-11-08 15:25:53 +0100 (Mon, 08 Nov 2010)
New Revision: 4172

Modified:
   trunk/OpenDNSSEC/signer/src/adapter/adfile.c
   trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c
   trunk/OpenDNSSEC/signer/src/daemon/engine.c
   trunk/OpenDNSSEC/signer/src/daemon/worker.c
   trunk/OpenDNSSEC/signer/src/ods-signer.c
   trunk/OpenDNSSEC/signer/src/parser/zonelistparser.c
   trunk/OpenDNSSEC/signer/src/scheduler/task.c
   trunk/OpenDNSSEC/signer/src/signer/domain.c
   trunk/OpenDNSSEC/signer/src/signer/nsec3params.c
   trunk/OpenDNSSEC/signer/src/signer/se_key.c
   trunk/OpenDNSSEC/signer/src/signer/zone.c
   trunk/OpenDNSSEC/signer/src/signer/zonedata.c
   trunk/OpenDNSSEC/signer/src/tools/toolutil.c
   trunk/OpenDNSSEC/signer/src/tools/zone_fetcher.c
   trunk/OpenDNSSEC/signer/src/util/file.c
Log:
coverity



Modified: trunk/OpenDNSSEC/signer/src/adapter/adfile.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/adapter/adfile.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/adapter/adfile.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -355,8 +355,7 @@
                     break;
                 } else {
                     se_log_error("error parsing RR at line %i (%s): %s",
-                        l&&*l?*l:0, ldns_get_errorstr_by_id(*status),
-                        line?line:"(null)");
+                        l&&*l?*l:0, ldns_get_errorstr_by_id(*status), line);
                     while (len >= 0) {
                         len = adfile_read_line(fd, line, l);
                     }

Modified: trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -226,6 +226,7 @@
                     (void)snprintf(buf, ODS_SE_MAXLINE, "Sign zone %s "
                         "failed.\n", tbd);
                     se_writen(sockfd, buf, strlen(buf));
+                    lock_basic_unlock(&cmdc->engine->tasklist->tasklist_lock);
                     return;
                 } else {
                     task->when = now;
@@ -727,9 +728,11 @@
     int flags = 0;
     int ret = 0;
 
-    se_log_assert(filename);
-    se_log_debug("create command handler to socket %s",
-        filename?filename:"(null)");
+    if (!filename) {
+        se_log_error("unable to create command handler, no filename");
+        return NULL;
+    }
+    se_log_debug("create command handler to socket %s", filename);
 
     /* new socket */
     listenfd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -755,9 +758,7 @@
     }
 
     /* no suprises */
-    if (filename) {
-        unlink(filename);
-    }
+    unlink(filename);
     bzero(&servaddr, sizeof(servaddr));
     servaddr.sun_family = AF_UNIX;
     strncpy(servaddr.sun_path, filename, sizeof(servaddr.sun_path) - 1);

Modified: trunk/OpenDNSSEC/signer/src/daemon/engine.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/daemon/engine.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/daemon/engine.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -85,7 +85,6 @@
     engine->gid = -1;
     engine->need_to_exit = 0;
     engine->need_to_reload = 0;
-    engine->signal = SIGNAL_INIT;
     lock_basic_init(&engine->signal_lock);
     lock_basic_set(&engine->signal_cond);
     return engine;
@@ -558,19 +557,15 @@
 static void
 engine_run(engine_type* engine, int single_run)
 {
-    sig_atomic_t signal = SIGNAL_RUN;
-
+    if (!engine) {
+        return;
+    }
     se_log_assert(engine);
 
-    lock_basic_lock(&engine->signal_lock);
     engine->signal = SIGNAL_RUN;
-    lock_basic_unlock(&engine->signal_lock);
-
     while (engine->need_to_exit == 0 && engine->need_to_reload == 0) {
-        lock_basic_lock(&engine->signal_lock);
-        signal = signal_capture(engine->signal);
-        lock_basic_unlock(&engine->signal_lock);
-        switch (signal) {
+        engine->signal = signal_capture(engine->signal);
+        switch (engine->signal) {
             case SIGNAL_RUN:
                 se_log_assert(1);
                 break;
@@ -583,7 +578,7 @@
             default:
                 se_log_warning("invalid signal captured: %d, keep running",
                     engine->signal);
-                signal = SIGNAL_RUN;
+                engine->signal = SIGNAL_RUN;
                 break;
         }
 
@@ -592,7 +587,6 @@
         }
 
         lock_basic_lock(&engine->signal_lock);
-        engine->signal = signal;
         if (engine->signal == SIGNAL_RUN && !single_run) {
            se_log_debug("engine taking a break");
            lock_basic_sleep(&engine->signal_cond, &engine->signal_lock, 3600);

Modified: trunk/OpenDNSSEC/signer/src/daemon/worker.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/daemon/worker.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/daemon/worker.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -58,10 +58,13 @@
     worker->task = NULL;
     worker->need_to_exit = 0;
     worker->type = type;
+    lock_basic_init(&worker->worker_lock);
+    lock_basic_set(&worker->worker_alarm);
+
+    lock_basic_lock(&worker->worker_lock);
     worker->sleeping = 0;
     worker->waiting = 0;
-    lock_basic_init(&worker->worker_lock);
-    lock_basic_set(&worker->worker_alarm);
+    lock_basic_unlock(&worker->worker_lock);
     return worker;
 }
 

Modified: trunk/OpenDNSSEC/signer/src/ods-signer.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/ods-signer.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/ods-signer.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -94,7 +94,6 @@
     int n = 0;
     int ret = 0;
     int cmd_written = 0;
-    int cmd_response = 0;
     fd_set rset;
     char buf[ODS_SE_MAXLINE];
 
@@ -126,16 +125,12 @@
             continue;
         }
 
-        if (cmd && cmd_written && cmd_response) {
-            /* normal termination */
-            return;
-        }
-
         if (FD_ISSET(sockfd, &rset)) {
             /* clear buffer */
-            for (i=0; i< ODS_SE_MAXLINE; i++) {
+            for (i=0; i < ODS_SE_MAXLINE; i++) {
                 buf[i] = 0;
             }
+            buf[ODS_SE_MAXLINE-1] = '\0';
 
             /* socket is readable */
             if ((n = read(sockfd, buf, ODS_SE_MAXLINE)) <= 0) {
@@ -153,9 +148,6 @@
                     /* weird termination */
                     fprintf(stderr, "signer engine terminated "
                         "prematurely\n");
-                    if (cmd) {
-                        se_free((void*)cmd);
-                    }
                     exit(1);
                 }
             }
@@ -166,7 +158,6 @@
                     ret = (int) write(fileno(stdout), buf, n-SE_CLI_CMDLEN);
                 }
                 buf[(n-SE_CLI_CMDLEN)] = '\0';
-                cmd_response = 1;
                 ret = 1;
             } else {
                 /* we can expect more */
@@ -179,7 +170,7 @@
             } else if (ret < 0) {
                 fprintf(stderr, "write error: %s\n", strerror(errno));
             }
-            if (se_strcmp(buf, ODS_SE_STOP_RESPONSE) == 0 || cmd_response) {
+            if (se_strcmp(buf, ODS_SE_STOP_RESPONSE) == 0) {
                 fprintf(stderr, "\n");
                 return;
             }
@@ -216,9 +207,6 @@
                 if (ret != 0) {
                     fprintf(stderr, "shutdown failed: %s\n",
                         strerror(errno));
-                    if (cmd) {
-                        se_free((void*)cmd);
-                    }
                     exit(1);
                 }
                 FD_CLR(fileno(fp), &rset);

Modified: trunk/OpenDNSSEC/signer/src/parser/zonelistparser.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/parser/zonelistparser.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/parser/zonelistparser.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -215,8 +215,7 @@
 
             /* and add it to the list */
             if (zonelist_add_zone(zl, new_zone) == NULL) {
-                se_log_error("unable to add zone %s to zone list",
-                    zone_name?zone_name:"(null)");
+                se_log_error("unable to add zone %s to zone list", zone_name);
             }
             se_free((void*) zone_name);
             xmlXPathFreeContext(xpathCtx);

Modified: trunk/OpenDNSSEC/signer/src/scheduler/task.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/scheduler/task.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/scheduler/task.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -132,12 +132,16 @@
     char* filename = NULL;
     FILE* fd = NULL;
 
-    se_log_assert(task);
+    if (!task) {
+        return;
+    }
 
-    if (task && task->who) {
+    if (task->who) {
         filename = se_build_path(task->who, ".task", 0);
         fd = se_fopen(filename, NULL, "w");
         se_free((void*)filename);
+    } else {
+        return;
     }
 
     if (fd) {
@@ -151,8 +155,7 @@
         se_fclose(fd);
     } else {
         se_log_warning("cannot backup task for zone %s: cannot open file "
-        "%s.task for writing",
-        task->who?task->who:"(null)", task->who?task->who:"(null)");
+        "%s.task for writing", task->who, task->who);
     }
     return;
 }
@@ -348,8 +351,11 @@
 
     se_log_debug("create task list");
     tl->tasks = ldns_rbtree_create(task_compare);
+    lock_basic_init(&tl->tasklist_lock);
+
+    lock_basic_lock(&tl->tasklist_lock);
     tl->loading = 0;
-    lock_basic_init(&tl->tasklist_lock);
+    lock_basic_unlock(&tl->tasklist_lock);
     return tl;
 }
 

Modified: trunk/OpenDNSSEC/signer/src/signer/domain.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/domain.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/signer/domain.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -1104,8 +1104,10 @@
         rrset_cleanup(rrset);
         node = ldns_rbtree_next(node);
     }
+    if (rrset_tree && rrset_tree->root != LDNS_RBTREE_NULL) {
+        se_rbnode_free(rrset_tree->root);
+    }
     if (rrset_tree) {
-        se_rbnode_free(rrset_tree->root);
         ldns_rbtree_free(rrset_tree);
     }
     return;

Modified: trunk/OpenDNSSEC/signer/src/signer/nsec3params.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/nsec3params.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/signer/nsec3params.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -62,7 +62,7 @@
         *salt = NULL;
         return 0;
     } else if (*salt_len % 2 != 0) {
-        se_log_error("invalid salt %s", salt_str?salt_str:"(null)");
+        se_log_error("invalid salt %s", salt_str);
         *salt = NULL;
         return 1;
     }
@@ -74,7 +74,7 @@
             salt_tmp[c/2] = (uint8_t) ldns_hexdigit_to_int(salt_str[c]) * 16 +
                                       ldns_hexdigit_to_int(salt_str[c+1]);
         } else {
-            se_log_error("invalid salt %s", salt_str?salt_str:"(null)");
+            se_log_error("invalid salt %s", salt_str);
             se_free((void*)salt_tmp);
             *salt = NULL;
             return 1;

Modified: trunk/OpenDNSSEC/signer/src/signer/se_key.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/se_key.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/signer/se_key.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -293,10 +293,14 @@
 
     search = list->first_key;
     for (i=0; i < list->count; i++) {
-        if (search && se_strcmp(search->locator, locator) == 0) {
-            return search;
+        if (search) {
+            if (se_strcmp(search->locator, locator) == 0) {
+                return search;
+            }
+            search = search->next;
+        } else {
+            break;
         }
-        search = search->next;
     }
     return NULL;
 }

Modified: trunk/OpenDNSSEC/signer/src/signer/zone.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/zone.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/signer/zone.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -1024,6 +1024,9 @@
         }
 
         task = tasklist_schedule_task(tl, zone->task, 1);
+        if (!task) {
+            se_log_error("failed to schedule task for zone %s", zone->name);
+        }
     }
 
     if (error) {

Modified: trunk/OpenDNSSEC/signer/src/signer/zonedata.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/zonedata.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/signer/zonedata.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -850,6 +850,11 @@
         zd->inbound_serial, zd->internal_serial, zd->outbound_serial,
         (uint32_t) time_now());
 
+    if (!sc->soa_serial) {
+        se_log_error("no serial type given");
+        return 1;
+    }
+
     if (se_strcmp(sc->soa_serial, "unixtime") == 0) {
         soa = se_max(zd->inbound_serial, (uint32_t) time_now());
         if (!DNS_SERIAL_GT(soa, prev)) {
@@ -884,8 +889,7 @@
         prev = soa;
         update = 0;
     } else {
-        se_log_error("unknown serial type %s",
-            sc->soa_serial?sc->soa_serial:"(null)");
+        se_log_error("unknown serial type %s", sc->soa_serial);
         return 1;
     }
 
@@ -1345,8 +1349,10 @@
         domain_cleanup(domain);
         node = ldns_rbtree_next(node);
     }
+    if (domain_tree && domain_tree->root != LDNS_RBTREE_NULL) {
+        se_rbnode_free(domain_tree->root);
+    }
     if (domain_tree) {
-        se_rbnode_free(domain_tree->root);
         ldns_rbtree_free(domain_tree);
     }
     return;

Modified: trunk/OpenDNSSEC/signer/src/tools/toolutil.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/tools/toolutil.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/tools/toolutil.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -80,7 +80,7 @@
 				line[li] = ' ';
 				li++;
 			}
-		} else if (c == ')' && multiline && !in_string) {
+		} else if (c == ')' && multiline) {
 			if (in_string) {
 				line[li] = c;
 				li++;

Modified: trunk/OpenDNSSEC/signer/src/tools/zone_fetcher.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/tools/zone_fetcher.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/tools/zone_fetcher.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -477,8 +477,7 @@
                 xpathCtx = xmlXPathNewContext(doc);
                 if (xpathCtx == NULL) {
                     se_log_error("zone fetcher can not create XPath "
-                        "context for %s; skipping zone",
-                        zone_name?zone_name:"(null)");
+                        "context for %s; skipping zone", zone_name);
                     /* Don't return? try to parse the rest of the zones? */
                     ret = xmlTextReaderRead(reader);
                     continue;
@@ -1362,6 +1361,12 @@
     /* read transfer configuration */
     config = new_config();
     config->pidfile = strdup(ODS_ZF_PIDFILE); /* not freed */
+    if (!config->pidfile) {
+        se_log_alert("zone fetcher error: no pidfile given");
+        free_config(config);
+        exit(EXIT_FAILURE);
+    }
+
     c = read_axfr_config(config_file, config);
     config->zonelist = read_zonelist(zonelist_file);
 
@@ -1385,8 +1390,7 @@
 
     /* write pidfile */
     if (writepid(config->pidfile, getpid()) != 0) {
-        se_log_error("write pidfile %s failed",
-            config->pidfile?config->pidfile:"(null)");
+        se_log_error("write pidfile %s failed", config->pidfile);
         se_log_info("zone fetcher exiting...");
         exit(EXIT_FAILURE);
     }

Modified: trunk/OpenDNSSEC/signer/src/util/file.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/util/file.c	2010-11-05 14:28:05 UTC (rev 4171)
+++ trunk/OpenDNSSEC/signer/src/util/file.c	2010-11-08 14:25:53 UTC (rev 4172)
@@ -330,7 +330,7 @@
     }
 
     buffer[ch-str] = '\0';
-    sprintf(buffer+(ch-str), "%s%s", newstr, ch+strlen(oldstr));
+    snprintf(buffer+(ch-str), SYSTEM_MAXLEN, "%s%s", newstr, ch+strlen(oldstr));
     return buffer;
 }
 




More information about the Opendnssec-commits mailing list