[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r4169 - in trunk/OpenDNSSEC/enforcer: ksm utils

Sion Lloyd sion at nominet.org.uk
Thu Nov 4 15:24:23 CET 2010


Author: sion
Date: 2010-11-04 15:24:23 +0100 (Thu, 04 Nov 2010)
New Revision: 4169

Modified:
   trunk/OpenDNSSEC/enforcer/ksm/datetime.c
   trunk/OpenDNSSEC/enforcer/ksm/ksm_list.c
   trunk/OpenDNSSEC/enforcer/ksm/ksm_policy.c
   trunk/OpenDNSSEC/enforcer/ksm/message.c
   trunk/OpenDNSSEC/enforcer/utils/ksmutil.c
Log:
Fix coverity reports.


Modified: trunk/OpenDNSSEC/enforcer/ksm/datetime.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/datetime.c	2010-11-04 14:19:59 UTC (rev 4168)
+++ trunk/OpenDNSSEC/enforcer/ksm/datetime.c	2010-11-04 14:24:23 UTC (rev 4169)
@@ -1039,7 +1039,7 @@
                     if (!temp) {
                         temp = atol(ptr);
                         got_temp = 1;
-                        if ((temp_interval <= INT_MIN) && (temp_interval >= INT_MAX)) {
+                        if ((temp_interval <= INT_MIN) || (temp_interval >= INT_MAX)) {
                             return(3);
                         }
                     }

Modified: trunk/OpenDNSSEC/enforcer/ksm/ksm_list.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/ksm_list.c	2010-11-04 14:19:59 UTC (rev 4168)
+++ trunk/OpenDNSSEC/enforcer/ksm/ksm_list.c	2010-11-04 14:24:23 UTC (rev 4169)
@@ -67,12 +67,15 @@
 {
     char*       sql = NULL;     /* SQL query */
     char*       sql2 = NULL;     /* SQL query */
+    char*       sql3 = NULL;     /* SQL query */
     int         status = 0;     /* Status return */
     char        stringval[KSM_INT_STR_SIZE];  /* For Integer to String conversion */
     DB_RESULT	result;         /* Result of the query */
     DB_ROW      row = NULL;     /* Row data */
     DB_RESULT	result2;         /* Result of the query */
     DB_ROW      row2 = NULL;     /* Row data */
+    DB_RESULT	result3;         /* Result of the query */
+    DB_ROW      row3 = NULL;     /* Row data */
 
     char*       temp_date = NULL; /* place to store date returned */
     char*       temp_pre_date = NULL; /* place to store pre-backup date returned */
@@ -131,6 +134,7 @@
     DusFree(sql);
     DbFreeRow(row);
     DbStringFree(temp_date);
+    DbStringFree(temp_pre_date);
     sql = NULL;
     row = NULL;
     temp_date = NULL;
@@ -180,33 +184,31 @@
     DbStringFree(temp_repo);
 
     /* List repos which need a backup commit */
-    sql2 = NULL;
-    row2 = NULL;
     temp_repo = NULL;
-    StrAppend(&sql2, "select s.name from keypairs k, securitymodules s ");
-    StrAppend(&sql2, "where s.id = k.securitymodule_id ");
+    StrAppend(&sql3, "select s.name from keypairs k, securitymodules s ");
+    StrAppend(&sql3, "where s.id = k.securitymodule_id ");
     if (repo_id != -1) {
-        StrAppend(&sql2, "and s.id = ");
+        StrAppend(&sql3, "and s.id = ");
         snprintf(stringval, KSM_INT_STR_SIZE, "%d", repo_id);
-        StrAppend(&sql2, stringval);
+        StrAppend(&sql3, stringval);
     }
-    StrAppend(&sql2, " and k.backup is null");
-    StrAppend(&sql2, " and k.pre_backup is not null");
-    StrAppend(&sql2, " group by s.name order by s.name");
+    StrAppend(&sql3, " and k.backup is null");
+    StrAppend(&sql3, " and k.pre_backup is not null");
+    StrAppend(&sql3, " group by s.name order by s.name");
 
-    DusEnd(&sql2);
+    DusEnd(&sql3);
 
-    status = DbExecuteSql(DbHandle(), sql2, &result2);
+    status = DbExecuteSql(DbHandle(), sql3, &result3);
 
     if (status == 0) {
-        status = DbFetchRow(result2, &row2);
+        status = DbFetchRow(result3, &row3);
         while (status == 0) {
             /* Got a row, print it */
-            DbString(row2, 0, &temp_repo);
+            DbString(row3, 0, &temp_repo);
 
             printf("Repository %s has keys prepared for back up which have not been committed\n", temp_repo);
             
-            status = DbFetchRow(result2, &row2);
+            status = DbFetchRow(result3, &row3);
         }
 
         /* Convert EOF status to success */
@@ -215,11 +217,11 @@
             status = 0;
         }
 
-        DbFreeResult(result2);
+        DbFreeResult(result3);
     }
 
-    DusFree(sql2);
-    DbFreeRow(row2);
+    DusFree(sql3);
+    DbFreeRow(row3);
     DbStringFree(temp_repo);
 
     return status;

Modified: trunk/OpenDNSSEC/enforcer/ksm/ksm_policy.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/ksm_policy.c	2010-11-04 14:19:59 UTC (rev 4168)
+++ trunk/OpenDNSSEC/enforcer/ksm/ksm_policy.c	2010-11-04 14:24:23 UTC (rev 4169)
@@ -809,7 +809,7 @@
     DB_RESULT       result;     /* Handle converted to a result object */
     DB_ROW          row = NULL; /* Row data */
 
-    if (policy == NULL || policy->name == NULL) {
+    if (policy == NULL || policy->name[0] == '\0') {
         return MsgLog(KSM_INVARG, "NULL policy or name");
     }
 

Modified: trunk/OpenDNSSEC/enforcer/ksm/message.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/ksm/message.c	2010-11-04 14:19:59 UTC (rev 4168)
+++ trunk/OpenDNSSEC/enforcer/ksm/message.c	2010-11-04 14:24:23 UTC (rev 4169)
@@ -387,7 +387,7 @@
         output = MsgGetOutput(status);
     }
     else {
-        sprintf(buffer, "?????: unknown message number %d", status);
+        snprintf(buffer, sizeof(buffer), "?????: unknown message number %d", status);
         output = MsgDefaultOutput;
     }
 

Modified: trunk/OpenDNSSEC/enforcer/utils/ksmutil.c
===================================================================
--- trunk/OpenDNSSEC/enforcer/utils/ksmutil.c	2010-11-04 14:19:59 UTC (rev 4168)
+++ trunk/OpenDNSSEC/enforcer/utils/ksmutil.c	2010-11-04 14:24:23 UTC (rev 4169)
@@ -1306,6 +1306,7 @@
     MemFree(zone_ids);
     StrFree(sql);
     StrFree(zonelist_filename);
+    StrFree(temp_name);
 
     return 0;
 }
@@ -2528,6 +2529,7 @@
         printf("Please specify a zone using the --zone flag\n");
         usage_keydsseen();
         StrFree(datetime);
+        db_disconnect(lock_fd);
         return(-1);
     } 
     else if (o_zone != NULL) {
@@ -3106,7 +3108,6 @@
     /* Check that we will be able to make the changes to kasp.xml */
     if ((test = fopen(kasp_filename, "ab"))==NULL) {
         printf("Cannot open kasp.xml for writing: %s\n", strerror(errno));
-        fclose(test);
         return(-1);
     } else {
         fclose(test);
@@ -3126,6 +3127,7 @@
         /* Something went wrong */
 
         MsgLog(KME_SQLFAIL, DbErrmsg(DbHandle()));
+        db_disconnect(lock_fd);
         return status;
     }
 
@@ -3159,6 +3161,8 @@
                     /* Quick check that we didn't run out of space */
                     if (size < 0 || size >= KSM_SQL_SIZE) {
                         printf("Couldn't construct SQL to kill orphaned keys\n");
+			db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         return -1;
                     }
 
@@ -3167,6 +3171,8 @@
                     /* Report any errors */
                     if (status != 0) {
                         printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+			db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         return status;
                     }
 
@@ -3174,6 +3180,8 @@
                     status = PurgeKeys(-1, policy->id);
                     if (status != 0) {
                         printf("Key purge failed for policy %s\n", policy->name);
+			db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         return status;
                     }
 
@@ -3187,6 +3195,8 @@
                     if (status != 0) 
                     { 
                         printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+			db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         return status; 
                     }
 
@@ -3199,6 +3209,8 @@
                     if (status != 0) 
                     { 
                         printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+			db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         return status; 
                     }
 
@@ -3207,6 +3219,7 @@
                     doc = del_policy_node(kasp_filename, policy->name);
                     if (doc == NULL) {
                         db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         StrFree(kasp_filename);
                         return(1);
                     }
@@ -3218,6 +3231,7 @@
                         printf("Could not save %s\n", kasp_filename);
                         StrFree(kasp_filename);
                         db_disconnect(lock_fd);
+			KsmPolicyFree(policy);
                         return(1);
                     }
 
@@ -3249,6 +3263,7 @@
 
     StrFree(kasp_filename);
     db_disconnect(lock_fd);
+    KsmPolicyFree(policy);
     return status;
 }
 
@@ -4121,6 +4136,7 @@
     xpathCtx = xmlXPathNewContext(doc);
     if(xpathCtx == NULL) {
         xmlFreeDoc(doc);
+	KsmPolicyFree(policy);
         return(1);
     }
 
@@ -4129,6 +4145,7 @@
     if(xpathObj == NULL) {
         xmlXPathFreeContext(xpathCtx);
         xmlFreeDoc(doc);
+	KsmPolicyFree(policy);
         return(1);
     }
 
@@ -6312,10 +6329,22 @@
         /* make sure that we have at least one zone */ 
         if (zone_count == 0) { 
             printf("No zones on policy %s, skipping...", policy->name);
+	    db_disconnect(lock_fd);
+	    if (ctx) {
+		    hsm_destroy_context(ctx);
+	    }
+	    hsm_close();
+            KsmPolicyFree(policy);
             return status; 
         } 
     } else {
         printf("Could not count zones on policy %s", policy->name);
+        db_disconnect(lock_fd);
+	if (ctx) {
+		hsm_destroy_context(ctx);
+	}
+	hsm_close();
+	KsmPolicyFree(policy);
         return status; 
     }
 
@@ -7324,6 +7353,7 @@
         /* Something went wrong */
 
         MsgLog(KME_SQLFAIL, DbErrmsg(DbHandle()));
+	StrFree(keyids);
         return status;
     }
 
@@ -7413,6 +7443,7 @@
     }
     else {
         printf("Moving to keystate %s not implemented yet\n", KsmKeywordStateValueToName(keystate));
+	StrFree(keyids);
         return -1;
     }
 
@@ -7805,6 +7836,7 @@
     int         where = 0;
     int         j = 0;
     DB_RESULT	result2;        /* Result of the query */
+    DB_RESULT	result3;        /* Result of the query */
     DB_ROW      row2 = NULL;    /* Row data */
     char*       insql1 = NULL;  /* SQL query */
     char*       insql2 = NULL;  /* SQL query */
@@ -7855,6 +7887,7 @@
             /* Report any errors */
             if (status != 0) {
                 printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+                DbFreeRow(row);
                 return status;
             }
 
@@ -7872,6 +7905,7 @@
             /* Report any errors */
             if (status != 0) {
                 printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+                DbFreeRow(row);
                 return status;
             }
 
@@ -7889,6 +7923,7 @@
             /* Report any errors */
             if (status != 0) {
                 printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+                DbFreeRow(row);
                 return status;
             }
            
@@ -7934,9 +7969,9 @@
 
                 size = snprintf(sql2, KSM_SQL_SIZE, "select zone_id from KEYDATA_VIEW where policy_id = %d and keytype = %d and state in (%d,%d)", policy_id, KSM_TYPE_KSK, KSM_STATE_PUBLISH, KSM_STATE_READY);
                 j=0;
-                status = DbExecuteSql(DbHandle(), sql2, &result2);
+                status = DbExecuteSql(DbHandle(), sql2, &result3);
                 if (status == 0) {
-                    status = DbFetchRow(result2, &row2);
+                    status = DbFetchRow(result3, &row2);
                     while (status == 0) {
                         /* Got a row, print it */
                         DbInt(row2, 0, &temp_zone_id);
@@ -7948,7 +7983,7 @@
                         StrAppend(&insql2, buffer);
                         j++;
 
-                        status = DbFetchRow(result2, &row2);
+                        status = DbFetchRow(result3, &row2);
                     }
 
                     /* Convert EOF status to success */
@@ -7957,7 +7992,7 @@
                         status = 0;
                     }
 
-                    DbFreeResult(result2);
+                    DbFreeResult(result3);
                 }
                 DbFreeRow(row2);
 
@@ -7967,6 +8002,7 @@
                 /* Quick check that we didn't run out of space */
                 if (size < 0 || size >= KSM_SQL_SIZE) {
                     printf("Couldn't construct SQL to promote standby key\n");
+		    DbFreeRow(row);
                     return -1;
                 }
 
@@ -7975,6 +8011,7 @@
                 /* Report any errors */
                 if (status != 0) {
                     printf("SQL failed: %s\n", DbErrmsg(DbHandle()));
+		    DbFreeRow(row);
                     return status;
                 }
             }
@@ -7990,6 +8027,7 @@
         DbFreeResult(result1);
     }
     DqsFree(sql);
+    DbFreeRow(row);
 
     StrFree(datetime);
     




More information about the Opendnssec-commits mailing list