[libvirt] [PATCH v2] lxc: Clang is complaining about possible NULL pointer.

Julio Faracco posted 1 patch 5 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20181107205702.14057-1-jcfaracco@gmail.com
Test syntax-check passed
src/lxc/lxc_container.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
[libvirt] [PATCH v2] lxc: Clang is complaining about possible NULL pointer.
Posted by Julio Faracco 5 years, 5 months ago
The array "mount" inside lxc_container is not being checked before for
loop. Clang syntax scan is complaining about this segmentation fault.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 src/lxc/lxc_container.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 918194dacd..d834bf01d7 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -867,9 +867,13 @@ static int lxcContainerSetReadOnly(void)
         }
     }
 
-    if (mounts)
-        qsort(mounts, nmounts, sizeof(mounts[0]),
-              virStringSortRevCompare);
+    if (!mounts) {
+        ret = 0;
+        goto cleanup;
+    }
+
+    qsort(mounts, nmounts, sizeof(mounts[0]),
+          virStringSortRevCompare);
 
     for (i = 0; i < nmounts; i++) {
         VIR_DEBUG("Bind readonly %s", mounts[i]);
@@ -883,9 +887,7 @@ static int lxcContainerSetReadOnly(void)
 
     ret = 0;
  cleanup:
-    for (i = 0; i < nmounts; i++)
-        VIR_FREE(mounts[i]);
-    VIR_FREE(mounts);
+    virStringListFreeCount(mounts, nmounts);
     endmntent(procmnt);
     return ret;
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] lxc: Clang is complaining about possible NULL pointer.
Posted by John Ferlan 5 years, 5 months ago

On 11/7/18 3:57 PM, Julio Faracco wrote:
> The array "mount" inside lxc_container is not being checked before for
> loop. Clang syntax scan is complaining about this segmentation fault.
> 
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  src/lxc/lxc_container.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>
(and pushed)

John

FWIW:
Ironically Coverity never complained about this one even though it's in
the category of things Coverity doesn't like either ;-)

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] lxc: Clang is complaining about possible NULL pointer.
Posted by Martin Kletzander 5 years, 5 months ago
On Wed, Nov 07, 2018 at 04:23:47PM -0500, John Ferlan wrote:
>
>
>On 11/7/18 3:57 PM, Julio Faracco wrote:
>> The array "mount" inside lxc_container is not being checked before for
>> loop. Clang syntax scan is complaining about this segmentation fault.
>>
>> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
>> ---
>>  src/lxc/lxc_container.c | 14 ++++++++------
>>  1 file changed, 8 insertions(+), 6 deletions(-)
>>
>
>Reviewed-by: John Ferlan <jferlan@redhat.com>
>(and pushed)
>
>John
>
>FWIW:
>Ironically Coverity never complained about this one even though it's in
>the category of things Coverity doesn't like either ;-)
>

My guess is that coverity was clever enough to know that thing can never happen
(it could happen only if nmounts is non-zero and mounts is NULL).

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