Skip to content
Snippets Groups Projects
Commit c4a1aa48 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Standards.ASN1.Decode: Set error mode on Stdio.Buffer.

Throw errors on buffer underflow.

Thanks to Joshua Rogers for the report and test vectors.

Fixes #10075.
parent 09203fe7
Branches
Tags
No related merge requests found
......@@ -109,6 +109,7 @@ protected array(int) read_identifier(Stdio.Buffer data)
({"universal","application","context","private"})[cls], const, tag, len);
data = [object(Stdio.Buffer)]data->read_buffer(len);
data->set_error_mode(1);
program(.Types.Object) p = types[ .Types.make_combined_tag(cls, tag) ];
......@@ -230,7 +231,7 @@ mapping(int:program(.Types.Object)) universal_types =
mapping(int:program(.Types.Object))|void types)
{
types = types ? universal_types+types : universal_types;
Stdio.Buffer buf = Stdio.Buffer(data);
Stdio.Buffer buf = Stdio.Buffer(data)->set_error_mode(1);
.Types.Object ret = der_decode(buf, types);
if( sizeof(buf) ) return 0;
return ret;
......
......@@ -3,6 +3,10 @@ START_MARKER
test_do( add_constant("Types", Standards.ASN1.Types); )
test_eval_error(Standards.ASN1.Decode.simple_der_decode(""))
test_eval_error(Standards.ASN1.Decode.secure_der_decode(""))
test_eval_error(Standards.ASN1.Decode.simple_der_decode(String.hex2string("a2184515521e4c5d26f05590543c696ca2bd04b7754a18107d7f62744fbcb3a52ee80de3dca53339c3f6b2196afe3c540adfeb92686029f2")))
test_eval_error(Standards.ASN1.Decode.secure_der_decode(String.hex2string("a2184515521e4c5d26f05590543c696ca2bd04b7754a18107d7f62744fbcb3a52ee80de3dca53339c3f6b2196afe3c540adfeb92686029f2")))
define(test_decode,[[
test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string($1-" ")))-"Standards.ASN1.",$2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment