[libvirt] [PATCH] util: Resolve coverity issues

Wang King posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170412082257.33868-1-king.wang@huawei.com
src/util/virsystemd.c | 2 ++
1 file changed, 2 insertions(+)
[libvirt] [PATCH] util: Resolve coverity issues
Posted by Wang King 7 years ago
Coverity complains about virBufferCurrentContent might be return null when calling
strlen, so check virBufferError first before calling strlen.
---
 src/util/virsystemd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index ceb1c1a..83737a2 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -135,6 +135,8 @@ virSystemdAppendValidMachineName(virBufferPtr buf,
     bool skip_dot = false;
 
     for (; *name; name++) {
+        if (virBufferError(buf))
+            break;
         if (strlen(virBufferCurrentContent(buf)) >= 64)
             break;
 
-- 
2.8.3


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: Resolve coverity issues
Posted by Peter Krempa 7 years ago
On Wed, Apr 12, 2017 at 16:22:57 +0800, Wang King wrote:

"resolve coverity issue" is not a good summary for a patch. It should
describe what the actual bug you are fixing is.

> Coverity complains about virBufferCurrentContent might be return null when calling
> strlen, so check virBufferError first before calling strlen.
> ---
>  src/util/virsystemd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
> index ceb1c1a..83737a2 100644
> --- a/src/util/virsystemd.c
> +++ b/src/util/virsystemd.c
> @@ -135,6 +135,8 @@ virSystemdAppendValidMachineName(virBufferPtr buf,
>      bool skip_dot = false;
>  
>      for (; *name; name++) {
> +        if (virBufferError(buf))
> +            break;
>          if (strlen(virBufferCurrentContent(buf)) >= 64)
>              break;

I'll tweak the commit message to crub mentions of coverity and replace
them by description of the actual problem and push this.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: Resolve coverity issues
Posted by Wang King 7 years ago
On 2017/4/12 16:35, Peter Krempa wrote:
> On Wed, Apr 12, 2017 at 16:22:57 +0800, Wang King wrote:
>
> "resolve coverity issue" is not a good summary for a patch. It should
> describe what the actual bug you are fixing is.
>
>> Coverity complains about virBufferCurrentContent might be return null when calling
>> strlen, so check virBufferError first before calling strlen.
>> ---
>>   src/util/virsystemd.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
>> index ceb1c1a..83737a2 100644
>> --- a/src/util/virsystemd.c
>> +++ b/src/util/virsystemd.c
>> @@ -135,6 +135,8 @@ virSystemdAppendValidMachineName(virBufferPtr buf,
>>       bool skip_dot = false;
>>   
>>       for (; *name; name++) {
>> +        if (virBufferError(buf))
>> +            break;
>>           if (strlen(virBufferCurrentContent(buf)) >= 64)
>>               break;
> I'll tweak the commit message to crub mentions of coverity and replace
> them by description of the actual problem and push this.
Thanks for your proposal, I have already send an other improved patch 
"util: fix potential segfault".

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