Reverted ltostr() changes as the cause a significant delay to the library.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 17 May 2014 07:11:10 +0000 (09:11 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 17 May 2014 07:16:07 +0000 (09:16 +0200)
The best approach would be to eliminate the need for ltostr() completely.
Added LTOSTR_MAX_SIZE, to avoid overflows.

lib/coding.c
lib/decoding.c
lib/element.c
lib/parser_aux.c
lib/parser_aux.h

index e4eb060..d6b7cf4 100644 (file)
@@ -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;
index f85451f..93bc962 100644 (file)
@@ -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)
index 3f31aa2..359b3ab 100644 (file)
@@ -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))
index 31d1770..effedb2 100644 (file)
@@ -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)
index f1e9a07..1f1aec2 100644 (file)
@@ -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);