File 0394-ic-Fix-correct-external-format-sizes.patch of Package erlang

From cdfc10af65b613a5315add29a3b7a89c6b513883 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 11 Jul 2018 18:27:54 +0200
Subject: [PATCH 1/3] ic: Fix correct external format sizes

longs, longlongs and wchar were too small on 64-bit
which could lead to potential buffer overflow at encoding.

__OE_DOUBLESZ__ was too big, probably due to old text format.
---
 lib/ic/c_src/oe_ei_decode_wstring.c |  2 +-
 lib/ic/include/ic.h                 | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/ic/c_src/oe_ei_decode_wstring.c b/lib/ic/c_src/oe_ei_decode_wstring.c
index 5b676fd579..66eaf66392 100644
--- a/lib/ic/c_src/oe_ei_decode_wstring.c
+++ b/lib/ic/c_src/oe_ei_decode_wstring.c
@@ -76,7 +76,7 @@ int oe_ei_decode_wstring(const char *buf, int *index, CORBA_wchar *p) {
     if (p) { /* Decoding part */
       
       /* Allocate temporary string */
-      tmp_space = (char*) malloc(length*(__OE_WCHARSZ__+1));
+      tmp_space = (char*) malloc((length + 1)*sizeof(char));
 
       if ((error_code = ei_decode_string(buf, index, tmp_space)) < 0)
 	return error_code;
diff --git a/lib/ic/include/ic.h b/lib/ic/include/ic.h
index 3dc5dbd4b5..1eb9e1e9d9 100644
--- a/lib/ic/include/ic.h
+++ b/lib/ic/include/ic.h
@@ -251,13 +251,13 @@ extern "C" {
 
 #define __OE_MEMCHUNK__   1024
 #define __OE_VSNSZ__         1
-#define __OE_LONGSZ__        7
-#define __OE_LONGLONGSZ__    7
-#define __OE_ULONGSZ__       7
-#define __OE_ULONGLONGSZ__   7
-#define __OE_DOUBLESZ__     32
+#define __OE_LONGSZ__        (3+sizeof(long))
+#define __OE_LONGLONGSZ__    (3+sizeof(long))
+#define __OE_ULONGSZ__       (3+sizeof(long))
+#define __OE_ULONGLONGSZ__   (3+sizeof(long))
+#define __OE_DOUBLESZ__      9
 #define __OE_CHARSZ__        2
-#define __OE_WCHARSZ__       7  
+#define __OE_WCHARSZ__       (3+sizeof(CORBA_wchar))
 #define __OE_TUPLEHDRSZ__    5
 #define __OE_LISTHDRSZ__     5
 
-- 
2.16.4

openSUSE Build Service is sponsored by