aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-11-30 11:56:50 +0100
committerGitHub <[email protected]>2017-11-30 11:56:50 +0100
commit3b3a617453af3ea5a731516585888c2373825a1d (patch)
tree02cbf85a6597461a8626adbfd5a4fc7d574738ba /erts/emulator
parent79f7815238673bbeea2b4551cc207768c348e5ce (diff)
parent864362749246d15355e904cf95248a634eebdfb7 (diff)
downloadotp-3b3a617453af3ea5a731516585888c2373825a1d.tar.gz
otp-3b3a617453af3ea5a731516585888c2373825a1d.tar.bz2
otp-3b3a617453af3ea5a731516585888c2373825a1d.zip
Merge pull request #1633 from sunboshan/atom-size-fix
Fix integer overflow when set a large maximum value for atom table OTP-14796
Diffstat (limited to 'erts/emulator')
-rw-r--r--erts/emulator/beam/atom.h2
-rw-r--r--erts/emulator/beam/index.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/erts/emulator/beam/atom.h b/erts/emulator/beam/atom.h
index be998a46bd..385120a8d9 100644
--- a/erts/emulator/beam/atom.h
+++ b/erts/emulator/beam/atom.h
@@ -36,7 +36,7 @@
/* Internal atom cache needs MAX_ATOM_TABLE_SIZE to be less than an
unsigned 32 bit integer. See external.c(erts_encode_ext_dist_header_setup)
for more details. */
-#define MAX_ATOM_TABLE_SIZE ((MAX_ATOM_INDEX + 1 < (UWORD_CONSTANT(1) << 32)) ? MAX_ATOM_INDEX + 1 : (UWORD_CONSTANT(1) << 32))
+#define MAX_ATOM_TABLE_SIZE ((MAX_ATOM_INDEX + 1 < (UWORD_CONSTANT(1) << 32)) ? MAX_ATOM_INDEX + 1 : ((UWORD_CONSTANT(1) << 31) - 1)) /* Here we use maximum signed interger value to avoid integer overflow */
#else
#define MAX_ATOM_TABLE_SIZE (MAX_ATOM_INDEX + 1)
#endif
diff --git a/erts/emulator/beam/index.c b/erts/emulator/beam/index.c
index a1f6f54543..7bf1a032c1 100644
--- a/erts/emulator/beam/index.c
+++ b/erts/emulator/beam/index.c
@@ -58,7 +58,7 @@ IndexTable*
erts_index_init(ErtsAlcType_t type, IndexTable* t, char* name,
int size, int limit, HashFunctions fun)
{
- Uint base_size = ((limit+INDEX_PAGE_SIZE-1)/INDEX_PAGE_SIZE)*sizeof(IndexSlot*);
+ Uint base_size = (((Uint)limit+INDEX_PAGE_SIZE-1)/INDEX_PAGE_SIZE)*sizeof(IndexSlot*);
hash_init(type, &t->htable, name, 3*size/4, fun);
t->size = 0;