diff options
author | Björn Gustavsson <[email protected]> | 2013-01-10 12:15:43 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-01-22 19:20:11 +0100 |
commit | 70caf52f1a7e09569c776bb1f99b0bf4737c63c2 (patch) | |
tree | 252d673222be3061d07ecf8148bab3357f792816 /lib/asn1/test/ber_decode_error.erl | |
parent | 844e2126e3b814f9fa058be367be3af745c7a80b (diff) | |
download | otp-70caf52f1a7e09569c776bb1f99b0bf4737c63c2.tar.gz otp-70caf52f1a7e09569c776bb1f99b0bf4737c63c2.tar.bz2 otp-70caf52f1a7e09569c776bb1f99b0bf4737c63c2.zip |
Correct error handling for the NIF functions
Also make sure that the error handling is contained within the
asn1rt_nif module and does not leak out to generated code.
Diffstat (limited to 'lib/asn1/test/ber_decode_error.erl')
-rw-r--r-- | lib/asn1/test/ber_decode_error.erl | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/lib/asn1/test/ber_decode_error.erl b/lib/asn1/test/ber_decode_error.erl index ff6e386a88..af0105bf26 100644 --- a/lib/asn1/test/ber_decode_error.erl +++ b/lib/asn1/test/ber_decode_error.erl @@ -21,31 +21,34 @@ -export([run/1]). --include_lib("test_server/include/test_server.hrl"). - run([]) -> - ?line {ok,B} = asn1_wrapper:encode('Constructed','S3',{'S3',17}), - ?line [T,L|V] = lists:flatten(B), - ?line Bytes = [T,L+3|V] ++ [2,1,3], - ?line case asn1_wrapper:decode('Constructed','S3',Bytes) of - {error,{asn1,{unexpected,_}}} -> ok - end, - %% Unexpected bytes must be accepted if there is an extensionmark - ?line {ok,{'S3ext',17}} = asn1_wrapper:decode('Constructed','S3ext',Bytes), - ok; -run([driver]) -> - %% test of OTP-4797, bad indata to driver does not cause an EXIT - ?line {error,_Reason} = asn1rt:decode('Constructed','S3',[3,5]), - ok; -run([nif]) -> - %% test of OTP-4797, bad indata to driver does not cause an EXIT - ?line {error,_Reason} = asn1rt:decode('Constructed','S3',[3,5]), - ok. - + {ok,B} = asn1_wrapper:encode('Constructed','S3',{'S3',17}), + [T,L|V] = lists:flatten(B), + Bytes = [T,L+3|V] ++ [2,1,3], + case asn1_wrapper:decode('Constructed','S3',Bytes) of + {error,{asn1,{unexpected,_}}} -> ok + end, + %% Unexpected bytes must be accepted if there is an extensionmark + {ok,{'S3ext',17}} = asn1_wrapper:decode('Constructed','S3ext',Bytes), + %% Truncated tag. + {error,{asn1,{invalid_tag,_}}} = + (catch 'Constructed':decode('I', <<31,255,255>>)), + %% Overlong tag. + {error,{asn1,{invalid_tag,_}}} = + (catch 'Constructed':decode('I', <<31,255,255,255,127>>)), + %% Invalid length. + {error,{asn1,{invalid_length,_}}} = + (catch 'Constructed':decode('I', <<8,255>>)), + %% Other errors. + {error,{asn1,{invalid_value,_}}} = + (catch 'Constructed':decode('I', <<>>)), + {error,{asn1,{invalid_value,_}}} = + (catch 'Constructed':decode('I', <<8,7>>)), + ok. |