aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2018-12-20 13:26:54 +0100
committerErlang/OTP <[email protected]>2018-12-20 13:26:54 +0100
commit5d2a5f23ed1251e487eab53ee19f8cbb56f7e22d (patch)
treef5e2d5189642c51ec44c2d15906c59128ab5b97d
parent64273c7e90fa079bdb633d60c632f48454eb4e82 (diff)
parent1e6ab2fdac21c7847b7fda32fed1ea35883a535e (diff)
downloadotp-5d2a5f23ed1251e487eab53ee19f8cbb56f7e22d.tar.gz
otp-5d2a5f23ed1251e487eab53ee19f8cbb56f7e22d.tar.bz2
otp-5d2a5f23ed1251e487eab53ee19f8cbb56f7e22d.zip
Merge branch 'sverker/fix-atomics-get-large-unsigned/PR-2061/OTP-15486' into maint-21
* sverker/fix-atomics-get-large-unsigned/PR-2061/OTP-15486: erts: Fix possible heap corruption getting atomics
-rw-r--r--erts/emulator/beam/erl_bif_atomics.c2
-rw-r--r--erts/emulator/test/atomics_SUITE.erl3
2 files changed, 4 insertions, 1 deletions
diff --git a/erts/emulator/beam/erl_bif_atomics.c b/erts/emulator/beam/erl_bif_atomics.c
index 092dbb3bd3..029831bd95 100644
--- a/erts/emulator/beam/erl_bif_atomics.c
+++ b/erts/emulator/beam/erl_bif_atomics.c
@@ -133,7 +133,7 @@ static ERTS_INLINE Eterm bld_atomic(Process* proc, AtomicsRef* p,
if ((Uint64)val <= MAX_SMALL)
return make_small((Sint) val);
else {
- Uint hsz = ERTS_UINT64_HEAP_SIZE(val);
+ Uint hsz = ERTS_UINT64_HEAP_SIZE((Uint64)val);
Eterm* hp = HAlloc(proc, hsz);
return erts_uint64_to_big(val, &hp);
}
diff --git a/erts/emulator/test/atomics_SUITE.erl b/erts/emulator/test/atomics_SUITE.erl
index 8c42354770..a5407c42ee 100644
--- a/erts/emulator/test/atomics_SUITE.erl
+++ b/erts/emulator/test/atomics_SUITE.erl
@@ -126,6 +126,9 @@ unsigned_limits(Config) when is_list(Config) ->
Min = atomics:add_get(Ref, 1, 1),
Max = atomics:sub_get(Ref, 1, 1),
+ atomics:put(Ref, 1, Max),
+ io:format("Max=~p~n", [atomics:get(Ref, 1)]),
+
{'EXIT',{badarg,_}} = (catch atomics:add(Ref, 1, Max+1)),
IncrMin = -(1 bsl (Bits-1)),
ok = atomics:put(Ref, 1, -IncrMin),