* asn1buf.h: New prototpyes for asn1buf_sync() and
authorTom Yu <tlyu@mit.edu>
Sat, 3 Jul 1999 09:00:15 +0000 (09:00 +0000)
committerTom Yu <tlyu@mit.edu>
Sat, 3 Jul 1999 09:00:15 +0000 (09:00 +0000)
asn1buf_skiptail().

* asn1buf.c (asn1buf_sync): Fix to deal with
constructed-indefinite encodings with trailing fields.  As a
result, this requires that the most recently read tag number be
passed in.
(asn1buf_skiptail): New helper function to skip trailing fields in
a constructed-indefinite encoding.

* krb5_decode.c (end_structure): Hack to deal with changed
asn1buf_sync().

* asn1_k_decode.c (end_structure, end_sequence_of): Hack to deal
with changed asn1buf_sync().

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11541 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/ChangeLog
src/lib/krb5/asn.1/asn1_k_decode.c
src/lib/krb5/asn.1/asn1buf.c
src/lib/krb5/asn.1/asn1buf.h
src/lib/krb5/asn.1/krb5_decode.c

index 33940ce205c2898c3b9df1e79ea887565870ac71..4b4d3184781473f74fb7821762359f8796ccfc8c 100644 (file)
@@ -1,3 +1,21 @@
+1999-07-03  Tom Yu  <tlyu@mit.edu>
+
+       * asn1buf.h: New prototpyes for asn1buf_sync() and
+       asn1buf_skiptail().
+
+       * asn1buf.c (asn1buf_sync): Fix to deal with
+       constructed-indefinite encodings with trailing fields.  As a
+       result, this requires that the most recently read tag number be
+       passed in.
+       (asn1buf_skiptail): New helper function to skip trailing fields in
+       a constructed-indefinite encoding.
+
+       * krb5_decode.c (end_structure): Hack to deal with changed
+       asn1buf_sync().
+
+       * asn1_k_decode.c (end_structure, end_sequence_of): Hack to deal
+       with changed asn1buf_sync().
+
 1999-06-30  Tom Yu  <tlyu@mit.edu>
 
        * asn1buf.c (asn1buf_sync): Interim fix for DCE compat problem
index 090fcc3d9394e9274b83747fa751f6f366b7d558..875db9ade5dcb72413314543dd3cb648fcd4ac3d 100644 (file)
@@ -56,7 +56,7 @@ if(class != APPLICATION || construction != CONSTRUCTED ||\
 #define get_field_body(var,decoder)\
 retval = decoder(&subbuf,&(var));\
 if(retval) return retval;\
-if(!taglen) next_tag();\
+if(!taglen) { next_tag(); }\
 next_tag()
 
 #define get_field(var,tagexpect,decoder)\
@@ -73,7 +73,7 @@ else var = optvalue
 #define get_lenfield_body(len,var,decoder)\
 retval = decoder(&subbuf,&(len),&(var));\
 if(retval) return retval;\
-if(!taglen) next_tag();\
+if(!taglen) { next_tag(); }\
 next_tag()
 
 #define get_lenfield(len,var,tagexpect,decoder)\
@@ -98,7 +98,8 @@ if(retval) return retval;\
 next_tag()
 
 #define end_structure()\
-asn1buf_sync(buf,&subbuf)
+retval = asn1buf_sync(buf,&subbuf,tagnum);\
+if(retval) return retval
 
 #define sequence_of(buf)\
 int size=0;\
@@ -110,7 +111,8 @@ retval = asn1buf_imbed(&seqbuf,buf,length);\
 if(retval) return retval
 
 #define end_sequence_of(buf)\
-asn1buf_sync(buf,&seqbuf)
+retval = asn1buf_sync(buf,&seqbuf,ASN1_TAGNUM_CEILING);\
+if(retval) return retval
 
 #define cleanup()\
 return 0
index 785b140918c4342c5706c9a6ac50d045dddb0fdc..648626ee5585d199ff0e773a2100954b48671cee 100644 (file)
@@ -52,6 +52,7 @@
 #include "asn1buf.h"
 #undef ASN1BUF_OMIT_INLINE_FUNCS
 #include <stdio.h>
+#include "asn1_get.h"
 
 asn1_error_code asn1buf_create(buf)
      asn1buf ** buf;
@@ -89,19 +90,51 @@ asn1_error_code asn1buf_imbed(subbuf, buf, length)
   return 0;
 }
 
-void asn1buf_sync(buf, subbuf)
+asn1_error_code asn1buf_sync(buf, subbuf, lasttag)
      asn1buf * buf;
      asn1buf * subbuf;
+     asn1_tagnum lasttag;
 {
+  asn1_error_code retval;
+
   if (subbuf->bound != buf->bound) {
     buf->next = subbuf->bound + 1;
   } else {
     /*
-     * indefinite length; this will suck
-     * XXX - need to skip fields somehow
+     * indefinite length:
+     *
+     * Note that asn1_get_tag() returns ASN1_TAGNUM_CEILING
+     * for an EOC encoding.
      */
+    if (lasttag != ASN1_TAGNUM_CEILING) {
+      retval = asn1buf_skiptail(subbuf);
+      if (retval) return retval;
+    }
     buf->next = subbuf->next;
   }
+  return 0;
+}
+
+asn1_error_code asn1buf_skiptail(buf)
+     asn1buf *buf;
+{
+  asn1_error_code retval;
+  asn1_class class;
+  asn1_construction construction;
+  asn1_tagnum tagnum;
+  int taglen;
+  int nestlevel;
+
+  nestlevel = 1;
+  while (nestlevel > 0) {
+    retval = asn1_get_tag(buf, &class, &construction, &tagnum, &taglen);
+    if (retval) return retval;
+    if (construction == CONSTRUCTED && taglen == 0)
+      nestlevel++;
+    if (tagnum == ASN1_TAGNUM_CEILING)
+      nestlevel--;
+  }
+  return 0;
 }
 
 asn1_error_code asn1buf_destroy(buf)
index 8103b9e030c8d05405c30ca38728a9f035789d40..1d7373ed053e4c8cdf24f12050f78ad2329e3958 100644 (file)
@@ -119,11 +119,18 @@ asn1_error_code asn1buf_imbed
              that case, ASN1_OVERRUN is returned)  *subbuf's current
              position starts at the beginning of *subbuf. */
 
-void asn1buf_sync
-       PROTOTYPE((asn1buf *buf, asn1buf *subbuf));
+asn1_error_code asn1buf_sync
+       PROTOTYPE((asn1buf *buf, asn1buf *subbuf, asn1_tagnum lasttag));
 /* requires  *subbuf is a sub-buffer of *buf, as created by asn1buf_imbed.
+             lasttag is a pointer to the last tagnumber read.
    effects   Synchronizes *buf's current position to match that of *subbuf. */
 
+asn1_error_code asn1buf_skiptail
+       PROTOTYPE((asn1buf *buf));
+/* requires  *buf is a subbuffer used in a decoding of a
+             constructed indefinite sequence.
+   effects   skips trailing fields. */
+
 asn1_error_code asn1buf_destroy
        PROTOTYPE((asn1buf **buf));
 /* effects   Deallocates **buf, sets *buf to NULL. */
index 8896bea05d91541f58cbef2281cba8526ac471d8..b0fe3160d1e9f4b47347536e3f84b05adcc1a609 100644 (file)
@@ -91,7 +91,8 @@ if(retval) clean_return(retval);\
 next_tag()
 
 #define end_structure()\
-asn1buf_sync(&buf,&subbuf)
+retval = asn1buf_sync(&buf,&subbuf,tagnum);\
+if (retval) clean_return(retval)
 
 /* process fields *******************************************/
 /* normal fields ************************/