Skip to contentSkip to conversation

qcow2: Silence covscan for g_realloc() result

PATCH In review Max Reitz 2 participants 2 messages Jun 17, 2014 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qcow2: Silence covscan for g_realloc() result

g_realloc() returns NULL iff zero bytes are requested. Covscan therefore reports a possible NULL pointer dereference, however, this is not applicable here, as nb_clusters is guaranteed to be non-zero.

In order to (hopefully) silence covscan, assert that the result of g_realloc() is truly non-NULL.

---
See https://bugzilla.redhat.com/show_bug.cgi?id=1102409 for covscan's output.

---
 block/qcow2-refcount.c | 1 +
 1 file changed, 1 insertion(+)
block/qcow2-refcount.c +1 -0
index 9507aef..4b81077 100644
@@ -1579,6 +1579,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
                         nb_clusters = (new_offset >> s->cluster_bits) + 1;
                         refcount_table = g_realloc(refcount_table,
                                 nb_clusters * sizeof(uint16_t));
+                        assert(refcount_table);
                         memset(&refcount_table[old_nb_clusters], 0, (nb_clusters
                                 - old_nb_clusters) * sizeof(uint16_t));
                     }
Signature · 1 line
2.0.0
#1 lore raw

Il 17/06/2014 19:57, Max Reitz ha scritto:

Quoted 20 lines

g_realloc() returns NULL iff zero bytes are requested. Covscan therefore reports a possible NULL pointer dereference, however, this is not applicable here, as nb_clusters is guaranteed to be non-zero.

In order to (hopefully) silence covscan, assert that the result of g_realloc() is truly non-NULL.

---
See https://bugzilla.redhat.com/show_bug.cgi?id=1102409 for covscan's output.

---
 block/qcow2-refcount.c | 1 +
 1 file changed, 1 insertion(+)
block/qcow2-refcount.c +0 -0
index 9507aef..4b81077 100644

block/qcow2-refcount.c int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,

Quoted 8 lines
block/qcow2-refcount.c +1 -1
@@ -1579,6 +1579,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
                         nb_clusters = (new_offset >> s->cluster_bits) + 1;
                         refcount_table = g_realloc(refcount_table,
                                 nb_clusters * sizeof(uint16_t));
+                        assert(refcount_table);
                         memset(&refcount_table[old_nb_clusters], 0, (nb_clusters
                                 - old_nb_clusters) * sizeof(uint16_t));
                     }
--

Please use a model like scripts/coverity-model.c to silence this and other errors.

Paolo