From 0fd671609f7b31a9313d1575434e7273f3f2cd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 4 Feb 2013 11:06:43 +0100 Subject: asn1_erl_nif: Correct broken length encoding The ber_bin_v2 backend calls a NIF function to decode all tags and lengths. Even open types that should not be decoded will also be decoded, which makes it necessary to later re-encode the data using a NIF function. The NIF function incorrectly encoded lengths. --- lib/asn1/c_src/asn1_erl_nif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/asn1/c_src/asn1_erl_nif.c b/lib/asn1/c_src/asn1_erl_nif.c index dbff14f9b3..26803a25a4 100644 --- a/lib/asn1/c_src/asn1_erl_nif.c +++ b/lib/asn1/c_src/asn1_erl_nif.c @@ -1134,8 +1134,8 @@ int ber_encode_length(size_t size, mem_chunk_t **curr, unsigned int *count) { (*curr)->curr -= 1; (*count)++; } else { - int chunks = size / 256 + 1; - if (ber_check_memory(curr, chunks + 1)) + int chunks = 0; + if (ber_check_memory(curr, 8)) return ASN1_ERROR; while (size > 0) @@ -1144,6 +1144,7 @@ int ber_encode_length(size_t size, mem_chunk_t **curr, unsigned int *count) { size >>= 8; (*curr)->curr -= 1; (*count)++; + chunks++; } *(*curr)->curr = chunks | 0x80; -- cgit v1.2.3