aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2018-10-11 21:08:36 +0200
committerErlang/OTP <[email protected]>2018-10-11 21:08:36 +0200
commit909517755e78f4bdc385c451f851f4499e0a163c (patch)
tree0f54e4bb8459c7a984375f3697cc71d1caf3cee7
parent1af9112d7fed1f3fb2cd1d05fb200d813c8ff3d3 (diff)
parent97dc5e7f396129222419811c173edc7fa767b0f8 (diff)
downloadotp-909517755e78f4bdc385c451f851f4499e0a163c.tar.gz
otp-909517755e78f4bdc385c451f851f4499e0a163c.tar.bz2
otp-909517755e78f4bdc385c451f851f4499e0a163c.zip
Merge branch 'sverker/r16/binary_to_atom-utf8-crash/ERL-474/OTP-14590' into maint-17
* sverker/r16/binary_to_atom-utf8-crash/ERL-474/OTP-14590: erts: Fix crash in binary_to_atom/term for invalid utf8
-rw-r--r--erts/emulator/beam/atom.c2
-rw-r--r--erts/emulator/test/bif_SUITE.erl3
-rw-r--r--erts/emulator/test/binary_SUITE.erl3
3 files changed, 7 insertions, 1 deletions
diff --git a/erts/emulator/beam/atom.c b/erts/emulator/beam/atom.c
index 84d2d5e3ed..f95582d1ab 100644
--- a/erts/emulator/beam/atom.c
+++ b/erts/emulator/beam/atom.c
@@ -137,7 +137,7 @@ atom_hash(Atom* obj)
while(len--) {
v = *p++;
/* latin1 clutch for r16 */
- if ((v & 0xFE) == 0xC2 && (*p & 0xC0) == 0x80) {
+ if (len && (v & 0xFE) == 0xC2 && (*p & 0xC0) == 0x80) {
v = (v << 6) | (*p & 0x3F);
p++; len--;
}
diff --git a/erts/emulator/test/bif_SUITE.erl b/erts/emulator/test/bif_SUITE.erl
index fbc229bc53..693c259f33 100644
--- a/erts/emulator/test/bif_SUITE.erl
+++ b/erts/emulator/test/bif_SUITE.erl
@@ -486,6 +486,9 @@ binary_to_atom(Config) when is_list(Config) ->
?line ?BADARG(binary_to_atom(id(<<255>>), utf8)),
?line ?BADARG(binary_to_atom(id(<<255,0>>), utf8)),
?line ?BADARG(binary_to_atom(id(<<16#C0,16#80>>), utf8)), %Overlong 0.
+ <<B:1/binary, _/binary>> = id(<<194, 163>>), %Truncated character ERL-474
+ ?BADARG(binary_to_atom(B, utf8)),
+
?line [?BADARG(binary_to_atom(<<C/utf8>>, utf8)) ||
C <- lists:seq(256, 16#D7FF)],
?line [?BADARG(binary_to_atom(<<C/utf8>>, utf8)) ||
diff --git a/erts/emulator/test/binary_SUITE.erl b/erts/emulator/test/binary_SUITE.erl
index 44e9e4f243..8a420a90c6 100644
--- a/erts/emulator/test/binary_SUITE.erl
+++ b/erts/emulator/test/binary_SUITE.erl
@@ -607,6 +607,9 @@ bad_binary_to_term(Config) when is_list(Config) ->
%% Bad float.
?line bad_bin_to_term(<<131,70,-1:64>>),
+
+ %% Truncated UTF8 character (ERL-474)
+ bad_bin_to_term(<<131,119,1,194,163>>),
ok.
bad_bin_to_term(BadBin) ->