[libvirt] [PATCH] util: fix potential segfault

Wang King posted 1 patch 7 years ago
Failed in applying to current master (apply log)
src/util/virsystemd.c | 2 ++
1 file changed, 2 insertions(+)
[libvirt] [PATCH] util: fix potential segfault
Posted by Wang King 7 years ago
virBufferCurrentContent might be get a NULL string, and then without checking it,
this can cause a segfault as strlen expects a string != NULL. Use virBufferCheckError
to check error 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..cfc4bdb 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 (virBufferCheckError(buf) < 0)
+            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: fix potential segfault
Posted by Peter Krempa 7 years ago
On Wed, Apr 12, 2017 at 17:38:06 +0800, Wang King wrote:
> virBufferCurrentContent might be get a NULL string, and then without checking it,
> this can cause a segfault as strlen expects a string != NULL. Use virBufferCheckError
> to check error before calling strlen.
> ---

I've already pushed the previous version with some changes to the commit
message.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list