File 0001-libcmpiutil-Fix-endianness-issues-in-embedded-object.patch of Package libcmpiutil

From e37b8a2831543a6dc82a771160dd270f1e647266 Mon Sep 17 00:00:00 2001
From: Thilo Boehm <tboehm@linux.vnet.ibm.com>
Date: Thu, 8 Aug 2013 15:27:53 +0200
Subject: [PATCH 1/3] libcmpiutil: Fix endianness issues in embedded object
 parsing

The auxiliary functions _set_int_prop/parse_int_property only
worked on little-endian archs as they performed an incorrect
reinterpretation of 64bit integers. Fixed by using the proper
CMPIValue union fields.

Signed-off-by: Thilo Boehm <tboehm@linux.vnet.ibm.com>
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
---
 eo_parser.c     | 35 ++++++++++++++++++++++-------------
 eo_parser_xml.c | 49 +++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/eo_parser.c b/eo_parser.c
index 36106fd..4c5b0ee 100644
--- a/eo_parser.c
+++ b/eo_parser.c
@@ -113,31 +113,40 @@ static int _set_int_prop(CMPISint64 value,
                          CMPIInstance *inst)
 {
         CMPIStatus s;
-        uint64_t unsigned_val = 0;
-        int64_t signed_val = 0;
+        CMPIValue val;
 
-        switch(type) {
+        switch (type) {
         case CMPI_uint64:
+                val.uint64 = (uint64_t) value;
+                break;
         case CMPI_uint32:
+                val.uint32 = (uint32_t) value;
+                break;
         case CMPI_uint16:
+                val.uint16 = (uint16_t) value;
+                break;
         case CMPI_uint8:
-                unsigned_val = (uint64_t) value;
-                s = CMSetProperty(inst,
-                                  prop,
-                                  (CMPIValue *) &(unsigned_val),
-                                  type);
+                val.uint8 = (uint8_t) value;
                 break;
         case CMPI_sint64:
+                val.sint64 = (int64_t) value;
+                break;
         case CMPI_sint32:
+                val.sint32 = (int32_t) value;
+                break;
         case CMPI_sint16:
+                val.sint16 = (int16_t) value;
+                break;
         case CMPI_sint8:
+                val.sint8 = (int8_t) value;
+                break;
         default:
-                signed_val = (int64_t) value;
-                s = CMSetProperty(inst,
-                                  prop,
-                                  (CMPIValue *) &(signed_val),
-                                  type);
+                return 0;
         }
+        s = CMSetProperty(inst,
+                          prop,
+                          &val,
+                          type);
 
         if (s.rc == CMPI_RC_OK)
                return 1;
diff --git a/eo_parser_xml.c b/eo_parser_xml.c
index c8b28cc..551a87b 100644
--- a/eo_parser_xml.c
+++ b/eo_parser_xml.c
@@ -90,11 +90,48 @@ static CMPIType parse_int_property(const char *string,
         if (sign) {
                 int64_t _val;
                 ret = sscanf(string, "%" SCNi64, &_val);
-                val->sint64 = _val;
+                switch (size) {
+                case 8:
+                        t = CMPI_sint8;
+                        val->sint8 = (int8_t) _val;
+                        break;
+                case 16:
+                        t = CMPI_sint16;
+                        val->sint16 = (int16_t) _val;
+                        break;
+                case 32:
+                        t = CMPI_sint32;
+                        val->sint32 = (int32_t) _val;
+                        break;
+                default:
+                case 64:
+                        t = CMPI_sint64;
+                        val->sint64 = (int64_t) _val;
+                        break;
+                };
         } else {
                 uint64_t _val;
                 ret = sscanf(string, "%" SCNu64, &_val);
-                val->uint64 = _val;
+                switch (size) {
+                case 8:
+                        t = CMPI_uint8;
+                        val->uint8 = (uint8_t) _val;
+                        break;
+                case 16:
+                        t = CMPI_uint16;
+                        val->uint16 = (uint16_t) _val;
+                        break;
+                case 32:
+                        t = CMPI_uint32;
+                        val->uint32 = (uint32_t) _val;
+                        break;
+                default:
+                case 64:
+                        t = CMPI_uint64;
+                        val->uint64 = (uint64_t) _val;
+                        break;
+
+                };
         }
 
         if (ret != 1) {
@@ -102,14 +139,6 @@ static CMPIType parse_int_property(const char *string,
                 return CMPI_null;
         }
 
-        switch (size) {
-        case 8:  t = sign ? CMPI_sint8  : CMPI_uint8;  break;
-        case 16: t = sign ? CMPI_sint16 : CMPI_uint16; break;
-        case 32: t = sign ? CMPI_sint32 : CMPI_uint32; break;
-        default:
-        case 64: t = sign ? CMPI_sint64 : CMPI_uint64; break;
-        };
-
         return t;
 }
 
-- 
2.36.1

openSUSE Build Service is sponsored by