Fixed uninit when the stacks has been switched.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 10 Jul 2007 17:19:20 +0000 (17:19 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 10 Jul 2007 17:19:20 +0000 (17:19 +0000)
lib/silcasn1/silcasn1.c
lib/silcasn1/silcasn1_decode.c
lib/silcasn1/silcasn1_i.h

index b80a1c0926b52cc108590682a54087b69026c780..ea1408e5508d1d01980229f13a129d3e7eb41e97 100644 (file)
@@ -84,8 +84,15 @@ SilcBool silc_asn1_init(SilcAsn1 asn1, SilcStack stack)
 
 void silc_asn1_uninit(SilcAsn1 asn1)
 {
+  SilcStack stack1 = asn1->stack1;
+
+  if (asn1->switched) {
+    stack1 = asn1->stack2;
+    asn1->stack2 = asn1->stack1;
+  }
+
   silc_stack_free(asn1->stack2);
-  silc_stack_free(asn1->stack1);
+  silc_stack_free(stack1);
 }
 
 #if defined(SILC_DEBUG)
index bcdd5e67932ad68651348e5dc216d4a6079844ac..883220fd60696c7d580de150e0753bbc588bb2fa 100644 (file)
@@ -948,6 +948,7 @@ SilcBool silc_asn1_decode(SilcAsn1 asn1, SilcBuffer src, ...)
       stack1 = asn1->stack1;
       asn1->stack1 = asn1->stack2;
       asn1->stack2 = stack1;
+      asn1->switched = !asn1->switched;
     }
   }
 
index 414ec2c92dbe9aab72afcd26d5f05221c3ef8f0b..8dd98752474063889e6111e2b4ecdc8fa8392967 100644 (file)
@@ -31,6 +31,7 @@ struct SilcAsn1Object {
   SilcStack stack2;            /* Internal stack for encoding/decoding */
   va_list ap;                  /* List of ASN.1 types given as argument */
   unsigned int accumul  : 1;   /* Accumulate memory from stack for result */
+  unsigned int switched  : 1;  /* Set when stack2 is set to stack1 */
 };
 
 /* The maximum depth for recursion in encoder and decoder. */