From 17f6fd613e8b7039526fbb063c6751fc0c2008c3 Mon Sep 17 00:00:00 2001 From: Mike Sassak Date: Fri, 13 Sep 2013 16:37:50 -0700 Subject: Check all pattern arguments passed to binary:matches/2 Including an empty binary as one of multiple patterns passed to binary:matches/2 would crash BEAM with: "Cannot reallocate 1342177280 bytes of memory (of type "tmp")". This ensures each pattern is valid before trying to match. --- erts/emulator/beam/erl_bif_binary.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erts/emulator/beam/erl_bif_binary.c b/erts/emulator/beam/erl_bif_binary.c index 0db19a1ee6..ff775691b3 100644 --- a/erts/emulator/beam/erl_bif_binary.c +++ b/erts/emulator/beam/erl_bif_binary.c @@ -927,6 +927,9 @@ static int do_binary_match_compile(Eterm argument, Eterm *tag, Binary **binp) if (binary_bitsize(b) != 0) { goto badarg; } + if (binary_size(b) == 0) { + goto badarg; + } ++words; characters += binary_size(b); } -- cgit v1.2.3 From e38c706e55c3b3df644ec4c04ae703df73ac044e Mon Sep 17 00:00:00 2001 From: Fredrik Gustafsson Date: Wed, 25 Sep 2013 09:34:41 +0200 Subject: stdlib: extended binary_module_SUITE to assure badarg for OTP-11350 --- lib/stdlib/test/binary_module_SUITE.erl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/stdlib/test/binary_module_SUITE.erl b/lib/stdlib/test/binary_module_SUITE.erl index 9b6f628aa9..00fb20489b 100644 --- a/lib/stdlib/test/binary_module_SUITE.erl +++ b/lib/stdlib/test/binary_module_SUITE.erl @@ -249,6 +249,10 @@ badargs(Config) when is_list(Config) -> binary:matches(<<1,2,3>>, {ac,ets:match_spec_compile([{'_',[],['$_']}])}, [{scope,{0,1}}])), + %% OTP-11350 + badarg = ?MASK_ERROR( + binary:matches(<<"foo">>, + [<<>>, <<"f">>])), ?line badarg = ?MASK_ERROR(binary:longest_common_prefix( [<<0:10000,1,2,4,1:3>>, -- cgit v1.2.3