File gsoap-02-typepuns.diff of Package gsoap

From: Jan Engelhardt <jengelh@medozas.de>
Date: 2011-07-01 17:19:00 +0200

src: fix invocation of undefined behavior

The int type may have a stricter alignment than buf, and as such,
using *(int *)buf is prone to undefined behavior, usually manifesting
themselves in SIGBUS.

---
 gsoap/stdsoap2.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: gsoap-2.8.3/gsoap/stdsoap2.c
===================================================================
--- gsoap-2.8.3.orig/gsoap/stdsoap2.c
+++ gsoap-2.8.3/gsoap/stdsoap2.c
@@ -2946,10 +2946,12 @@ int
 SOAP_FMAC2
 soap_rand()
 { unsigned char buf[4];
+  int r;
   if (!soap_ssl_init_done)
     soap_ssl_init();
   RAND_pseudo_bytes(buf, 4);
-  return *(int*)buf;
+  memcpy(&r, buf, sizeof(r));
+  return r;
 }
 #endif
 #endif
openSUSE Build Service is sponsored by