[libvirt] [dbus PATCH] util: fix virtDBusUtilDecodeUUID

Pavel Hrdina posted 1 patch 23 weeks ago
Failed in applying to current master (apply log)
src/util.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

[libvirt] [dbus PATCH] util: fix virtDBusUtilDecodeUUID

Posted by Pavel Hrdina 23 weeks ago
This function is supposed to convert ASCII character into its hex
representation, however the current implementation was wrong because
the first comparison would be false for all printable characters.  In
most cases it worked but for example '$' which is 0x24 in HEX would be
incorrectly converted to 0x2[ which is obviously wrong.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1647823

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util.c b/src/util.c
index 9e11285..103bb29 100644
--- a/src/util.c
+++ b/src/util.c
@@ -182,11 +182,12 @@ virtDBusUtilDecodeUUID(const gchar *uuid)
 }
 
 static guchar
-virtDBusUtilNumToHexchar(const guchar c)
+virtDBusUtilNumToHexchar(const guchar n)
 {
+    guchar c = n & 0x0f;
     if (c < 10)
         return '0' + c;
-    return 'a' + (c & 0x0f) - 10;
+    return 'a' + c - 10;
 }
 
 static guchar
-- 
2.20.1

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

Re: [libvirt] [dbus PATCH] util: fix virtDBusUtilDecodeUUID

Posted by Michal Privoznik 23 weeks ago
On 1/8/19 9:01 AM, Pavel Hrdina wrote:
> This function is supposed to convert ASCII character into its hex
> representation, however the current implementation was wrong because
> the first comparison would be false for all printable characters.  In
> most cases it worked but for example '$' which is 0x24 in HEX would be
> incorrectly converted to 0x2[ which is obviously wrong.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1647823
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/util.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

ACK

Michal

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