aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2013-10-16 16:28:21 +0200
committerSverker Eriksson <[email protected]>2013-11-18 20:19:51 +0100
commitd5b6c6f0bd96108d788cdfb9be15059125b3d87f (patch)
tree738c1ba0806110f3f4161a2366cf06592ed2eb25
parentf10ea68ce28e9b93ce614b5f829b1ca7f4cc753f (diff)
downloadotp-d5b6c6f0bd96108d788cdfb9be15059125b3d87f.tar.gz
otp-d5b6c6f0bd96108d788cdfb9be15059125b3d87f.tar.bz2
otp-d5b6c6f0bd96108d788cdfb9be15059125b3d87f.zip
erts: Add erlang wrappers to binary_to_term
to not expose the trapping BIF in the stacktrace when it throws badarg.
-rw-r--r--erts/emulator/beam/bif.tab8
-rw-r--r--erts/emulator/beam/external.c6
-rw-r--r--erts/preloaded/ebin/erlang.beambin97500 -> 97740 bytes
-rw-r--r--erts/preloaded/ebin/erts_internal.beambin3780 -> 4084 bytes
-rw-r--r--erts/preloaded/src/erlang.erl18
-rw-r--r--erts/preloaded/src/erts_internal.erl12
-rw-r--r--lib/tools/test/xref_SUITE.erl4
7 files changed, 32 insertions, 16 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab
index 3b7bb56885..9f3de5f780 100644
--- a/erts/emulator/beam/bif.tab
+++ b/erts/emulator/beam/bif.tab
@@ -45,7 +45,6 @@ bif erlang:apply/3
bif erlang:atom_to_list/1
bif erlang:binary_to_list/1
bif erlang:binary_to_list/3
-bif erlang:binary_to_term/1
bif erlang:crc32/1
bif erlang:crc32/2
bif erlang:crc32_combine/3
@@ -152,6 +151,8 @@ bif erts_internal:port_command/3
bif erts_internal:port_control/3
bif erts_internal:port_close/1
bif erts_internal:port_connect/2
+bif erts_internal:binary_to_term/1
+bif erts_internal:binary_to_term/2
bif erts_internal:request_system_task/3
bif erts_internal:check_process_code/2
@@ -479,11 +480,6 @@ bif erlang:call_on_load_function/1
bif erlang:finish_after_on_load/2
#
-# New Bifs in R13B4
-#
-bif erlang:binary_to_term/2
-
-#
# The binary match bifs (New in R14A - EEP9)
#
diff --git a/erts/emulator/beam/external.c b/erts/emulator/beam/external.c
index 0d2de1b199..e3e199b198 100644
--- a/erts/emulator/beam/external.c
+++ b/erts/emulator/beam/external.c
@@ -1476,7 +1476,7 @@ static Eterm binary_to_term_int(Process* p, Uint32 flags, Eterm bin, Binary* con
erts_set_gc_state(p, 1);
}
BUMP_REDS(p, (initial_reds - ctx->reds) / B2T_BYTES_PER_REDUCTION);
- BIF_ERROR(p, BADARG);
+ BIF_ERROR(p, BADARG & ~EXF_SAVETRACE);
case B2TDone:
b2t_destroy_context(ctx);
@@ -1522,7 +1522,7 @@ static Eterm binary_to_term_int(Process* p, Uint32 flags, Eterm bin, Binary* con
BIF_TRAP1(&binary_to_term_trap_export, p, ctx->trap_bin);
}
-BIF_RETTYPE binary_to_term_1(BIF_ALIST_1)
+BIF_RETTYPE erts_internal_binary_to_term_1(BIF_ALIST_1)
{
/*SVERK if (++sverk_cnt % 1000 == 0) {
erts_fprintf(stderr, "Call #%u to binary_to_term_int()\n", sverk_cnt);
@@ -1534,7 +1534,7 @@ BIF_RETTYPE binary_to_term_1(BIF_ALIST_1)
return binary_to_term_int(BIF_P, 0, BIF_ARG_1, NULL);
}
-BIF_RETTYPE binary_to_term_2(BIF_ALIST_2)
+BIF_RETTYPE erts_internal_binary_to_term_2(BIF_ALIST_2)
{
Eterm opts;
Eterm opt;
diff --git a/erts/preloaded/ebin/erlang.beam b/erts/preloaded/ebin/erlang.beam
index 159c91e37c..63fa535427 100644
--- a/erts/preloaded/ebin/erlang.beam
+++ b/erts/preloaded/ebin/erlang.beam
Binary files differ
diff --git a/erts/preloaded/ebin/erts_internal.beam b/erts/preloaded/ebin/erts_internal.beam
index 9d8a4cfd00..6c7dcff420 100644
--- a/erts/preloaded/ebin/erts_internal.beam
+++ b/erts/preloaded/ebin/erts_internal.beam
Binary files differ
diff --git a/erts/preloaded/src/erlang.erl b/erts/preloaded/src/erlang.erl
index e521c6fc3d..7b59f6c8b4 100644
--- a/erts/preloaded/src/erlang.erl
+++ b/erts/preloaded/src/erlang.erl
@@ -362,15 +362,25 @@ binary_to_list(_Binary, _Start, _Stop) ->
%% binary_to_term/1
-spec binary_to_term(Binary) -> term() when
Binary :: ext_binary().
-binary_to_term(_Binary) ->
- erlang:nif_error(undefined).
+binary_to_term(Binary) ->
+ %% This BIF may throw badarg while trapping
+ try
+ erts_internal:binary_to_term(Binary)
+ catch
+ error:Reason -> erlang:error(Reason,[Binary])
+ end.
%% binary_to_term/2
-spec binary_to_term(Binary, Opts) -> term() when
Binary :: ext_binary(),
Opts :: [safe].
-binary_to_term(_Binary, _Opts) ->
- erlang:nif_error(undefined).
+binary_to_term(Binary, Opts) ->
+ %% This BIF may throw badarg while trapping
+ try
+ erts_internal:binary_to_term(Binary,Opts)
+ catch
+ error:Reason -> erlang:error(Reason,[Binary,Opts])
+ end.
%% bit_size/1
%% Shadowed by erl_bif_types: erlang:bit_size/1
diff --git a/erts/preloaded/src/erts_internal.erl b/erts/preloaded/src/erts_internal.erl
index c8e8e7e069..d6a185482e 100644
--- a/erts/preloaded/src/erts_internal.erl
+++ b/erts/preloaded/src/erts_internal.erl
@@ -29,7 +29,7 @@
-module(erts_internal).
-export([await_port_send_result/3]).
-
+-export([binary_to_term/1, binary_to_term/2]).
-export([port_command/3, port_connect/2, port_close/1,
port_control/3, port_call/3, port_info/1, port_info/2]).
@@ -160,3 +160,13 @@ request_system_task(_Pid, _Prio, _Request) ->
check_process_code(_Module, _OptionList) ->
erlang:nif_error(undefined).
+-spec binary_to_term(Binary) -> term() when
+ Binary :: binary().
+binary_to_term(_Binary) ->
+ erlang:nif_error(undefined).
+
+-spec binary_to_term(Binary, Opts) -> term() when
+ Binary :: binary(),
+ Opts :: [safe].
+binary_to_term(_Binary, _Opts) ->
+ erlang:nif_error(undefined).
diff --git a/lib/tools/test/xref_SUITE.erl b/lib/tools/test/xref_SUITE.erl
index dc06678b8e..cdb5646b9f 100644
--- a/lib/tools/test/xref_SUITE.erl
+++ b/lib/tools/test/xref_SUITE.erl
@@ -2,7 +2,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2000-2012. All Rights Reserved.
+%% Copyright Ericsson AB 2000-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -1099,6 +1099,7 @@ read_expected(Version) ->
{POS1+1,{FF,{mod17,fun17,0}}},
{POS1+2,{FF,{erlang,spawn,1}}},
{POS1+2,{FF,{read,local,0}}},
+ {POS1+3,{FF,{erlang,binary_to_term,1}}},
{POS1+3,{FF,{erlang,spawn,1}}},
{POS1+4,{FF,{dist,func,0}}},
{POS1+4,{FF,{erlang,spawn,1}}},
@@ -1212,7 +1213,6 @@ read_expected(Version) ->
OKB1 = [{POS13+1,{FF,{erts_debug,apply,4}}},
{POS13+2,{FF,{erts_debug,apply,4}}},
{POS13+3,{FF,{erts_debug,apply,4}}},
- {POS1+3, {FF,{erlang,binary_to_term,1}}},
{POS3+1, {FF,{erlang,spawn,3}}},
{POS3+2, {FF,{erlang,spawn,3}}},
{POS3+3, {FF,{erlang,spawn_link,3}}},