[libvirt] [PATCH] vircapstest: Avoid (im)possible strcmp call with NULL argument

Jiri Denemark posted 1 patch 6 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/031de26f6537f061bd226156237945e89d744185.1510609491.git.jdenemar@redhat.com
tests/vircapstest.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[libvirt] [PATCH] vircapstest: Avoid (im)possible strcmp call with NULL argument
Posted by Jiri Denemark 6 years, 5 months ago
Some compiler may get confused and decide we are calling strcmp with
NULL argument from test_virCapsDomainDataLookupLXC. Although this does
not really happen since the call is guarded with
(data->machinetype != expect_machinetype), using STRNEQ_NULLABLE is
easier to understand, less fragile, and doing so makes sure strcmp is
never called with NULL argument.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tests/vircapstest.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tests/vircapstest.c b/tests/vircapstest.c
index 95829133d0..05ec802f35 100644
--- a/tests/vircapstest.c
+++ b/tests/vircapstest.c
@@ -188,11 +188,10 @@ doCapsCompare(virCapsPtr caps,
         goto error;
     }
 
-    if (data->machinetype != expect_machinetype &&
-        STRNEQ(data->machinetype, expect_machinetype)) {
+    if (STRNEQ_NULLABLE(data->machinetype, expect_machinetype)) {
         fprintf(stderr, "data->machinetype=%s doesn't match "
                 "expect_machinetype=%s\n",
-                data->machinetype, expect_machinetype);
+                NULLSTR(data->machinetype), NULLSTR(expect_machinetype));
         goto error;
     }
 
-- 
2.15.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] vircapstest: Avoid (im)possible strcmp call with NULL argument
Posted by Michal Privoznik 6 years, 5 months ago
On 11/13/2017 10:44 PM, Jiri Denemark wrote:
> Some compiler may get confused and decide we are calling strcmp with
> NULL argument from test_virCapsDomainDataLookupLXC. Although this does
> not really happen since the call is guarded with
> (data->machinetype != expect_machinetype), using STRNEQ_NULLABLE is
> easier to understand, less fragile, and doing so makes sure strcmp is
> never called with NULL argument.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  tests/vircapstest.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list