Skip to contentSkip to conversation

test-resv-mem: Fix CID 1523911

PATCH In review Eric Auger 3 participants 4 messages Nov 10, 2023 – Nov 13, 2023

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH 1/1 test-resv-mem: Fix CID 1523911

Coverity complains about passing "&expected" to "run_range_inverse_array", which dereferences null "expected". I guess the problem is that the compare_ranges() loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given the g_assert_cmpint() just before the loop. So the code looks safe to me.

Nevertheless adding a test on expected before the loop to get rid of the warning.

Fixes CID 1523901
Reported-by Coverity (CID 1523901)

---

Hope this fixes the Coverity warning as I cannot test.

---
 tests/unit/test-resv-mem.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/unit/test-resv-mem.c +4 -0
index 5963274e2c..cd8f7318cc 100644
@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges,
     print_ranges("out", ranges);
     print_ranges("expected", expected);
 #endif
+    if (!expected) {
+        g_assert_true(!ranges);
+        return;
+    }
     g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected));
     for (l = ranges, e = expected; l ; l = l->next, e = e->next) {
         Range *r = (Range *)l->data;
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Eric Auger

Coverity complains about passing "&expected" to "run_range_inverse_array", which dereferences null "expected". I guess the problem is that the compare_ranges() loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given the g_assert_cmpint() just before the loop. So the code looks safe to me.

Nevertheless adding a test on expected before the loop to get rid of the warning.

Fixes CID 1523901
Reported-by Coverity (CID 1523901)

---

Hope this fixes the Coverity warning as I cannot test.

---
  tests/unit/test-resv-mem.c | 4 ++++
  1 file changed, 4 insertions(+)
tests/unit/test-resv-mem.c +0 -0
index 5963274e2c..cd8f7318cc 100644

tests/unit/test-resv-mem.c static void compare_ranges(const char *prefix, GList *ranges, · line 53

Quoted 10 lines
tests/unit/test-resv-mem.c +4 -0
@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges,
      print_ranges("out", ranges);
      print_ranges("expected", expected);
  #endif
+    if (!expected) {
+        g_assert_true(!ranges);
+        return;
+    }
      g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected));
      for (l = ranges, e = expected; l ; l = l->next, e = e->next) {
          Range *r = (Range *)l->data;

I'll queue it (unless somebody else wants to take this?).

#2 lore raw
Quoted 40 lines · Thomas Huth
Quoted 26 lines · Eric Auger

Coverity complains about passing "&expected" to "run_range_inverse_array", which dereferences null "expected". I guess the problem is that the compare_ranges() loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given the g_assert_cmpint() just before the loop. So the code looks safe to me.

Nevertheless adding a test on expected before the loop to get rid of the warning.

Fixes CID 1523901
Reported-by Coverity (CID 1523901)

---

Hope this fixes the Coverity warning as I cannot test.
---
  tests/unit/test-resv-mem.c | 4 ++++

  1 file changed, 4 insertions(+)
tests/unit/test-resv-mem.c +0 -0
index 5963274e2c..cd8f7318cc 100644

tests/unit/test-resv-mem.c static void compare_ranges(const char *prefix, GList *ranges, · line 53

Quoted 10 lines
tests/unit/test-resv-mem.c +4 -0
@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges,
       print_ranges("out", ranges);
       print_ranges("expected", expected);
   #endif
+    if (!expected) {
+        g_assert_true(!ranges);
+        return;
+    }
       g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected));
       for (l = ranges, e = expected; l ; l = l->next, e = e->next) {
           Range *r = (Range *)l->data;
Quoted 1 line

I'll queue it (unless somebody else wants to take this?).

There is also another fix for the same series :

https://lore.kernel.org/qemu-devel/[email protected]/

I was waiting to have a little more for VFIO to queue both but they could go through your queue also.

Thanks,

C.

#3 lore raw
Quoted 44 lines · Cédric Le Goater
Quoted 41 lines · Thomas Huth
Quoted 36 lines · Eric Auger

Coverity complains about passing "&expected" to "run_range_inverse_array", which dereferences null "expected". I guess the problem is that the compare_ranges() loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given the g_assert_cmpint() just before the loop. So the code looks safe to me.

Nevertheless adding a test on expected before the loop to get rid of the warning.

Fixes CID 1523901
Reported-by Coverity (CID 1523901)

---

Hope this fixes the Coverity warning as I cannot test.
---
  tests/unit/test-resv-mem.c | 4 ++++

  1 file changed, 4 insertions(+)
tests/unit/test-resv-mem.c +4 -0
index 5963274e2c..cd8f7318cc 100644
@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList 
 *ranges,
       print_ranges("out", ranges);
       print_ranges("expected", expected);
   #endif
+    if (!expected) {
+        g_assert_true(!ranges);
+        return;
+    }
       g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected));
       for (l = ranges, e = expected; l ; l = l->next, e = e->next) {
Quoted 1 line

          Range *r = (Range *)l->data;

Quoted 1 line

I'll queue it (unless somebody else wants to take this?).

Quoted 7 lines

There is also another fix for the same series :

https://lore.kernel.org/qemu-devel/[email protected]/

I was waiting to have a little more for VFIO to queue both but they could go through your queue also.

I'm just looking at patches that affect tests/ ... the other fix is not related to that, so I won't pick up that one.

Thomas