Hi,

this series of patches fixes some issues in ding-libs. Patch 0003 should
fix Coverity issues 10035-10040 and 0004 and 0005 the remaining open
issues.

bye,
Sumit
From cbca2590b09e035a6b1bfe7b10d466c48f3a9f0b Mon Sep 17 00:00:00 2001
From: Sumit Bose <sb...@redhat.com>
Date: Mon, 24 Jan 2011 11:15:17 +0100
Subject: [PATCH 1/5] Fix implicit declaration error

---
 ini/ini_valueobj.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/ini/ini_valueobj.c b/ini/ini_valueobj.c
index a90fa45..8c378ac 100644
--- a/ini/ini_valueobj.c
+++ b/ini/ini_valueobj.c
@@ -28,6 +28,7 @@
 #include "ref_array.h"
 #include "ini_comment.h"
 #include "ini_defines.h"
+#include "ini_valueobj.h"
 #include "trace.h"
 
 struct value_obj {
-- 
1.7.3.3

From 60e1691f0773c66594fc91b027ff832289fcc573 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sb...@redhat.com>
Date: Mon, 24 Jan 2011 11:32:30 +0100
Subject: [PATCH 2/5] Do not ignore the return value of system()

---
 ini/ini_valueobj_ut.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/ini/ini_valueobj_ut.c b/ini/ini_valueobj_ut.c
index 767a64c..fd7c6b8 100644
--- a/ini/ini_valueobj_ut.c
+++ b/ini/ini_valueobj_ut.c
@@ -609,7 +609,10 @@ int vo_copy_test(void)
 
 int vo_show_test(void)
 {
-    VOOUT(system("cat test.ini"));
+    if (verbose) {
+        return system("cat test.ini");
+    }
+
     return EOK;
 }
 
-- 
1.7.3.3

From 6833b0eb88c8779fd76c5628a03a987ec03dac83 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sb...@redhat.com>
Date: Mon, 24 Jan 2011 11:33:50 +0100
Subject: [PATCH 3/5] Ensure error_string() never returns NULL

A Coverity check indicated that ther are platforms where strerror() will
return NULL for unknown, e.g. negative error numbers. Chances are that
these platforms will have problems with NULL arguments to printf() too.
---
 dhash/examples/dhash_test.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/dhash/examples/dhash_test.c b/dhash/examples/dhash_test.c
index 6c02de1..a2dfa77 100644
--- a/dhash/examples/dhash_test.c
+++ b/dhash/examples/dhash_test.c
@@ -35,10 +35,21 @@ int verbose = 0;
 
 const char *error_string(int error)
 {
+    const char *str;
+
     if (IS_HASH_ERROR(error))
         return hash_error_string(error);
 
-    return strerror(error);
+    if (error < 0) {
+        return "Negative error codes are not supported.";
+    }
+
+    str = strerror(error);
+    if (str == NULL) {
+        return "strerror() returned NULL.";
+    }
+
+    return str;
 }
 
 char *key_string(hash_key_t *key)
-- 
1.7.3.3

From 0ccdecf6ab27a71e98e802dc8414ed030871a70c Mon Sep 17 00:00:00 2001
From: Sumit Bose <sb...@redhat.com>
Date: Mon, 24 Jan 2011 11:59:25 +0100
Subject: [PATCH 4/5] Fix error codes in other_create_test()

It was possible that other_create_test() returns EOK although an error
occurred. The caller then falsely assumes that struct value_obj is
allocated. This should fix Coverity issue 10078.
---
 ini/ini_valueobj_ut.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ini/ini_valueobj_ut.c b/ini/ini_valueobj_ut.c
index fd7c6b8..82951e6 100644
--- a/ini/ini_valueobj_ut.c
+++ b/ini/ini_valueobj_ut.c
@@ -233,7 +233,7 @@ int other_create_test(FILE *ff, struct value_obj **vo)
     if (strncmp(fullstr, expected, strlen(expected) + 1) != 0) {
         printf("The expected value is different.\n%s\n", fullstr);
         value_destroy(new_vo);
-        return error;
+        return EINVAL;
     }
 
     /* Get value's origin */
@@ -247,7 +247,7 @@ int other_create_test(FILE *ff, struct value_obj **vo)
     if (origin != INI_VALUE_READ) {
         printf("The expected origin is different.\n%d\n", origin);
         value_destroy(new_vo);
-        return error;
+        return EINVAL;
     }
 
     /* Get value's line */
@@ -261,7 +261,7 @@ int other_create_test(FILE *ff, struct value_obj **vo)
     if (line != 1) {
         printf("The expected line is different.\n%d\n", origin);
         value_destroy(new_vo);
-        return error;
+        return EINVAL;
     }
 
     /* Get comment from the value */
@@ -276,7 +276,7 @@ int other_create_test(FILE *ff, struct value_obj **vo)
     if (ic == NULL) {
         printf("The expected comment to be there.\n");
         value_destroy(new_vo);
-        return error;
+        return EINVAL;
     }
 
     VOOUT(ini_comment_print(ic, stdout));
@@ -300,7 +300,7 @@ int other_create_test(FILE *ff, struct value_obj **vo)
         /* But this should not happen anyways -
          * it will be coding error.
          */
-        return error;
+        return EINVAL;
     }
 
     /* Put comment back */
-- 
1.7.3.3

From 3b8b217f7c75bc19d01f31c43d651c2441a3b5be Mon Sep 17 00:00:00 2001
From: Sumit Bose <sb...@redhat.com>
Date: Mon, 24 Jan 2011 12:09:36 +0100
Subject: [PATCH 5/5] Check if malloc() failed

The should fix Coverity issue 10074.
---
 dhash/examples/dhash_example.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/dhash/examples/dhash_example.c b/dhash/examples/dhash_example.c
index c7eac3d..06a3d2d 100644
--- a/dhash/examples/dhash_example.c
+++ b/dhash/examples/dhash_example.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <errno.h>
 #include "dhash.h"
 
 struct my_data_t {
@@ -47,7 +48,14 @@ bool visit_callback(hash_entry_t *entry, void *user_data)
 
 struct my_data_t *new_data(int foo, const char *bar)
 {
-    struct my_data_t *my_data = malloc(sizeof(struct my_data_t));
+    struct my_data_t *my_data;
+
+    my_data = malloc(sizeof(struct my_data_t));
+    if (my_data == NULL) {
+        fprintf(stderr, "malloc() failed.\n");
+        return NULL;
+    }
+
     my_data->foo = foo;
     strncpy(my_data->bar, bar, sizeof(my_data->bar));
     return my_data;
@@ -61,9 +69,15 @@ int main(int argc, char **argv)
     hash_entry_t *entry;
     unsigned long i, n_entries;
     int error;
-    struct my_data_t *my_data = new_data(1024, "Hello World!");
+    struct my_data_t *my_data;
     unsigned long count;
 
+    my_data = new_data(1024, "Hello World!");
+    if (my_data == NULL) {
+        fprintf(stderr, "new_data() failed.\n");
+        return ENOMEM;
+    }
+
     /* Create a hash table */
     error = hash_create(10, &table, delete_callback,  NULL);
     if (error != HASH_SUCCESS) {
-- 
1.7.3.3

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to