diff options
author | Hans Bolinder <[email protected]> | 2017-11-08 12:41:23 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2017-11-28 13:03:46 +0100 |
commit | 2ead5d429fe87ffedf0134d918c3b404e9fa70fe (patch) | |
tree | 16b677eafefde736d7c17307d7ec5f6979c8edc0 /lib/stdlib/test/base64_SUITE.erl | |
parent | f3756139b99a77a29dd7325d0b2d706eed8a881f (diff) | |
download | otp-2ead5d429fe87ffedf0134d918c3b404e9fa70fe.tar.gz otp-2ead5d429fe87ffedf0134d918c3b404e9fa70fe.tar.bz2 otp-2ead5d429fe87ffedf0134d918c3b404e9fa70fe.zip |
stdlib: Do not check base64 input more than needed
Often the decode functions return a function_clause error, but not
always, and the errors have not been consistent between modifications
of the base64 module.
Now the errors are returned as they happen--no attempt to make them
look nice is done. The alternative, to ensure that, for example,
{badarg, Culprit} is always returned upon bad input, was deemed
pointless.
Diffstat (limited to 'lib/stdlib/test/base64_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/base64_SUITE.erl | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/stdlib/test/base64_SUITE.erl b/lib/stdlib/test/base64_SUITE.erl index 1715b2ebe6..1fc4c3fc0e 100644 --- a/lib/stdlib/test/base64_SUITE.erl +++ b/lib/stdlib/test/base64_SUITE.erl @@ -97,10 +97,9 @@ base64_otp_5635(Config) when is_list(Config) -> <<"===">> = base64:decode(base64:encode("===")), ok. %%------------------------------------------------------------------------- -%% OTP-6279: Guard needed so that function fails in a correct -%% way for faulty input, i.e. function_clause. +%% OTP-6279: Make sure illegal characters are rejected when decoding. base64_otp_6279(Config) when is_list(Config) -> - {'EXIT',{function_clause, _}} = (catch base64:decode("dGVzda==a")), + {'EXIT',_} = (catch base64:decode("dGVzda==a")), ok. %%------------------------------------------------------------------------- %% Encode and decode big binaries. @@ -115,7 +114,13 @@ big(Config) when is_list(Config) -> %%------------------------------------------------------------------------- %% Make sure illegal characters are rejected when decoding. illegal(Config) when is_list(Config) -> - {'EXIT',{function_clause, _}} = (catch base64:decode("()")), + %% A few samples with different error reasons. Nothing can be + %% assumed about the reason for the crash. + {'EXIT',_} = (catch base64:decode("()")), + {'EXIT',_} = (catch base64:decode(<<19:8,20:8,21:8,22:8>>)), + {'EXIT',_} = (catch base64:decode([19,20,21,22])), + {'EXIT',_} = (catch base64:decode_to_string(<<19:8,20:8,21:8,22:8>>)), + {'EXIT',_} = (catch base64:decode_to_string([19,20,21,22])), ok. %%------------------------------------------------------------------------- %% mime_decode and mime_decode_to_string have different implementations |