diff options
author | John Ferlan <jferlan@redhat.com> | 2019-11-03 07:55:21 -0500 |
---|---|---|
committer | John Ferlan <jferlan@redhat.com> | 2019-11-06 11:27:12 -0500 |
commit | 3f3f74dbc755a09c161069967fc84e860edcd262 (patch) | |
tree | b7d0d93479b3f16fa0af9a24d779b0c34632b365 /tests/virbitmaptest.c | |
parent | 77180d0f703c60ea511a695c12a4f49f186531e2 (diff) | |
download | libvirt-3f3f74dbc755a09c161069967fc84e860edcd262.tar.gz |
tests: Fix logic to not have possible NULL deref
It's possible that virBitmapNewString returns NULL with an error
string (and not an allocation failure that would abort); however, if
virBitmapToString is called with a NULL @bitmap, then it will fail
in an ugly manner. So rather than have if (!map && !str) logic, split
the checks for each variable.
Found by Coverity
Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'tests/virbitmaptest.c')
-rw-r--r-- | tests/virbitmaptest.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 545e9272df..2808d9c880 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -682,9 +682,11 @@ test13(const void *opaque G_GNUC_UNUSED) for (i = 0; i < G_N_ELEMENTS(strings); i++) { map = virBitmapNewString(strings[i]); - str = virBitmapToString(map, false, true); + if (!map) + goto cleanup; - if (!map || !str) + str = virBitmapToString(map, false, true); + if (!str) goto cleanup; if (STRNEQ(strings[i], str)) { |