From: Tom Yu Date: Sat, 3 Jul 1999 09:00:15 +0000 (+0000) Subject: * asn1buf.h: New prototpyes for asn1buf_sync() and X-Git-Tag: krb5-1.1-beta1~80 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a7328a02e366d9ae1d6894c01a886e0cd5a2c52f;p=krb5.git * 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(). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11541 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index 33940ce20..4b4d31847 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,21 @@ +1999-07-03 Tom Yu + + * 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 * asn1buf.c (asn1buf_sync): Interim fix for DCE compat problem diff --git a/src/lib/krb5/asn.1/asn1_k_decode.c b/src/lib/krb5/asn.1/asn1_k_decode.c index 090fcc3d9..875db9ade 100644 --- a/src/lib/krb5/asn.1/asn1_k_decode.c +++ b/src/lib/krb5/asn.1/asn1_k_decode.c @@ -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 diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c index 785b14091..648626ee5 100644 --- a/src/lib/krb5/asn.1/asn1buf.c +++ b/src/lib/krb5/asn.1/asn1buf.c @@ -52,6 +52,7 @@ #include "asn1buf.h" #undef ASN1BUF_OMIT_INLINE_FUNCS #include +#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) diff --git a/src/lib/krb5/asn.1/asn1buf.h b/src/lib/krb5/asn.1/asn1buf.h index 8103b9e03..1d7373ed0 100644 --- a/src/lib/krb5/asn.1/asn1buf.h +++ b/src/lib/krb5/asn.1/asn1buf.h @@ -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. */ diff --git a/src/lib/krb5/asn.1/krb5_decode.c b/src/lib/krb5/asn.1/krb5_decode.c index 8896bea05..b0fe3160d 100644 --- a/src/lib/krb5/asn.1/krb5_decode.c +++ b/src/lib/krb5/asn.1/krb5_decode.c @@ -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 ************************/