LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0231-Assert-that-sz-MAX_ARITYVAL-in-make_arityval-sz.patch of Package erlang (Project home:Ledest:erlang:20)

From a091bcc99dd1c8ab5dc5e5f5e80ef254383170f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Mon, 5 Mar 2018 14:03:29 +0100
Subject: [PATCH 1/2] Assert that sz <= MAX_ARITYVAL in make_arityval(sz)

---
 erts/emulator/beam/bif.c      | 2 +-
 erts/emulator/beam/erl_term.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c
index d7a25adccb..92d49a6def 100644
--- a/erts/emulator/beam/bif.c
+++ b/erts/emulator/beam/bif.c
@@ -3171,7 +3171,7 @@ BIF_RETTYPE list_to_integer_2(BIF_ALIST_2)
 static int do_float_to_charbuf(Process *p, Eterm efloat, Eterm list, 
 			char *fbuf, int sizeof_fbuf) {
 
-    const static int arity_two = make_arityval(2);
+    Eterm arity_two = make_arityval(2);
     int decimals = SYS_DEFAULT_FLOAT_DECIMALS;
     int compact = 0;
     enum fmt_type_ {
diff --git a/erts/emulator/beam/erl_term.h b/erts/emulator/beam/erl_term.h
index 842802f8d9..b263be0738 100644
--- a/erts/emulator/beam/erl_term.h
+++ b/erts/emulator/beam/erl_term.h
@@ -317,7 +317,8 @@ _ET_DECLARE_CHECKED(Uint,header_arity,Eterm)
 #define MAX_ARITYVAL            ((((Uint)1) << 24) - 1)
 #define ERTS_MAX_TUPLE_SIZE     MAX_ARITYVAL
 
-#define make_arityval(sz)	_make_header((sz),_TAG_HEADER_ARITYVAL)
+#define make_arityval(sz)	(ASSERT((sz) <= MAX_ARITYVAL), \
+                                 _make_header((sz),_TAG_HEADER_ARITYVAL))
 #define is_arity_value(x)	(((x) & _TAG_HEADER_MASK) == _TAG_HEADER_ARITYVAL)
 #define is_sane_arity_value(x)	((((x) & _TAG_HEADER_MASK) == _TAG_HEADER_ARITYVAL) && \
 				 (((x) >> _HEADER_ARITY_OFFS) <= MAX_ARITYVAL))
-- 
2.16.2