From e47b2a0651ffe1867c844968ade7f6127957bf13 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 17 May 2014 09:11:10 +0200 Subject: Reverted ltostr() changes as the cause a significant delay to the library. The best approach would be to eliminate the need for ltostr() completely. Added LTOSTR_MAX_SIZE, to avoid overflows. --- lib/coding.c | 4 ++-- lib/decoding.c | 6 +++--- lib/element.c | 2 +- lib/parser_aux.c | 2 +- lib/parser_aux.h | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/coding.c b/lib/coding.c index e4eb060..d6b7cf4 100644 --- a/lib/coding.c +++ b/lib/coding.c @@ -594,7 +594,7 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der, int *counter, { asn1_node p; int tag_len, is_tag_implicit; - unsigned char class, class_implicit = 0, temp[SIZEOF_UNSIGNED_INT * 3 + 1]; + unsigned char class, class_implicit = 0, temp[MAX(SIZEOF_UNSIGNED_INT * 3 + 1, LTOSTR_MAX_SIZE)]; unsigned long tag_implicit = 0; unsigned char tag_der[MAX_TAG_LEN]; @@ -1012,7 +1012,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len, char *ErrorDescription) { asn1_node node, p, p2; - unsigned char temp[SIZEOF_UNSIGNED_LONG_INT * 3 + 1]; + unsigned char temp[MAX(LTOSTR_MAX_SIZE, SIZEOF_UNSIGNED_LONG_INT * 3 + 1)]; int counter, counter_old, len2, len3, tlen, move, max_len, max_len_old; int err; unsigned char *der = ider; diff --git a/lib/decoding.c b/lib/decoding.c index f85451f..93bc962 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -302,7 +302,7 @@ _asn1_get_objectid_der (const unsigned char *der, int der_len, int *ret_len, { int len_len, len, k; int leading; - char temp[20]; + char temp[LTOSTR_MAX_SIZE]; unsigned long val, val1; *ret_len = 0; @@ -1952,7 +1952,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len2; if (len3 > 0) { - _asn1_ltostr (counter + len3, temp, sizeof(temp)); + _asn1_ltostr (counter + len3, temp); tlen = strlen (temp); if (tlen > 0) @@ -2035,7 +2035,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, counter += len2; if (len3) { - _asn1_ltostr (counter + len3, temp, sizeof(temp)); + _asn1_ltostr (counter + len3, temp); tlen = strlen (temp); if (tlen > 0) diff --git a/lib/element.c b/lib/element.c index 3f31aa2..359b3ab 100644 --- a/lib/element.c +++ b/lib/element.c @@ -130,7 +130,7 @@ int _asn1_append_sequence_set (asn1_node node) { asn1_node p, p2; - char temp[10]; + char temp[LTOSTR_MAX_SIZE]; long n; if (!node || !(node->down)) diff --git a/lib/parser_aux.c b/lib/parser_aux.c index 31d1770..effedb2 100644 --- a/lib/parser_aux.c +++ b/lib/parser_aux.c @@ -536,7 +536,7 @@ char * _asn1_ltostr (long v, char *str) { long d, r; - char temp[20]; + char temp[LTOSTR_MAX_SIZE]; int count, k, start; if (v < 0) diff --git a/lib/parser_aux.h b/lib/parser_aux.h index f1e9a07..1f1aec2 100644 --- a/lib/parser_aux.h +++ b/lib/parser_aux.h @@ -52,6 +52,7 @@ void _asn1_delete_list (void); void _asn1_delete_list_and_nodes (void); +#define LTOSTR_MAX_SIZE 20 char *_asn1_ltostr (long v, char *str); asn1_node _asn1_find_up (asn1_node node); -- cgit v1.2.3