From 18ba61167c89f65a6d861acf69460cff18b5a2cb Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 1 Nov 1999 21:08:55 +0000 Subject: * krb5_decode.c (begin_structure): Update to deal with indefinite encodings better; also call asn1_get_sequence(). * asn1_k_decode.c (sequence_of): Update to deal with indefinite encodings better. (begin_structure): Update to deal with indefinite encodings better; also call asn1_get_sequence(). * asn1_get.h: Update prototypes for asn1_get_tag_indef(), asn1_get_tag(), asn1_get_sequence(), asn1_get_length(). * asn1_get.c (asn1_get_tag_indef): New function; get tag info, lengths, etc. as well as flag indicating whether the length is indefinite. (asn1_get_tag): Modify to just call asn1_get_tag_indef(). (asn1_get_sequence): Call asn1_get_tag_indef() in order to determine whether encoding is indefinite length. (asn1_get_length): Add "indef" arg to indicate whether an encoding has an indefinite length. * asn1buf.h: Update asn1buf_imbed() prototype. * asn1buf.c (asn1buf_imbed): Add "indef" arg so that we don't treat a definite zero-length encoding as an indefinite encoding. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11890 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/asn.1/ChangeLog | 27 +++++++++++++++++++++++++++ src/lib/krb5/asn.1/asn1_get.c | 32 +++++++++++++++++++++++++++----- src/lib/krb5/asn.1/asn1_get.h | 10 ++++++++-- src/lib/krb5/asn.1/asn1_k_decode.c | 12 ++++++------ src/lib/krb5/asn.1/asn1buf.c | 5 +++-- src/lib/krb5/asn.1/asn1buf.h | 3 ++- src/lib/krb5/asn.1/krb5_decode.c | 7 +++---- 7 files changed, 76 insertions(+), 20 deletions(-) (limited to 'src/lib') diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index 96ec80012..2d9b70eea 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,30 @@ +1999-11-01 Tom Yu + + * krb5_decode.c (begin_structure): Update to deal with indefinite + encodings better; also call asn1_get_sequence(). + + * asn1_k_decode.c (sequence_of): Update to deal with indefinite + encodings better. + (begin_structure): Update to deal with indefinite encodings + better; also call asn1_get_sequence(). + + * asn1_get.h: Update prototypes for asn1_get_tag_indef(), + asn1_get_tag(), asn1_get_sequence(), asn1_get_length(). + + * asn1_get.c (asn1_get_tag_indef): New function; get tag info, + lengths, etc. as well as flag indicating whether the length is + indefinite. + (asn1_get_tag): Modify to just call asn1_get_tag_indef(). + (asn1_get_sequence): Call asn1_get_tag_indef() in order to + determine whether encoding is indefinite length. + (asn1_get_length): Add "indef" arg to indicate whether an encoding + has an indefinite length. + + * asn1buf.h: Update asn1buf_imbed() prototype. + + * asn1buf.c (asn1buf_imbed): Add "indef" arg so that we don't + treat a definite zero-length encoding as an indefinite encoding. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/krb5/asn.1/asn1_get.c b/src/lib/krb5/asn.1/asn1_get.c index 39750bc74..20334a2fc 100644 --- a/src/lib/krb5/asn.1/asn1_get.c +++ b/src/lib/krb5/asn.1/asn1_get.c @@ -26,12 +26,14 @@ #include "asn1_get.h" -asn1_error_code asn1_get_tag(buf, class, construction, tagnum, retlen) +asn1_error_code +asn1_get_tag_indef(buf, class, construction, tagnum, retlen, indef) asn1buf * buf; asn1_class * class; asn1_construction * construction; asn1_tagnum * tagnum; int * retlen; + int * indef; { asn1_error_code retval; @@ -48,21 +50,36 @@ asn1_error_code asn1_get_tag(buf, class, construction, tagnum, retlen) } retval = asn1_get_id(buf,class,construction,tagnum); if(retval) return retval; - retval = asn1_get_length(buf,retlen); + retval = asn1_get_length(buf,retlen,indef); if(retval) return retval; return 0; } -asn1_error_code asn1_get_sequence(buf, retlen) +asn1_error_code +asn1_get_tag(buf, class, construction, tagnum, retlen) + asn1buf *buf; + asn1_class *class; + asn1_construction *construction; + asn1_tagnum *tagnum; + int *retlen; +{ + asn1_error_code retval; + int indef; + + return asn1_get_tag_indef(buf, class, construction, tagnum, retlen, &indef); +} + +asn1_error_code asn1_get_sequence(buf, retlen, indef) asn1buf * buf; int * retlen; + int * indef; { asn1_error_code retval; asn1_class class; asn1_construction construction; asn1_tagnum tagnum; - retval = asn1_get_tag(buf,&class,&construction,&tagnum,retlen); + retval = asn1_get_tag_indef(buf,&class,&construction,&tagnum,retlen,indef); if(retval) return retval; if(retval) return (krb5_error_code)retval; if(class != UNIVERSAL || construction != CONSTRUCTED || @@ -109,13 +126,16 @@ asn1_error_code asn1_get_id(buf, class, construction, tagnum) return 0; } -asn1_error_code asn1_get_length(buf, retlen) +asn1_error_code asn1_get_length(buf, retlen, indef) asn1buf * buf; int * retlen; + int * indef; { asn1_error_code retval; asn1_octet o; + if (indef != NULL) + *indef = 0; retval = asn1buf_remove_octet(buf,&o); if(retval) return retval; if((o&0x80) == 0){ @@ -129,6 +149,8 @@ asn1_error_code asn1_get_length(buf, retlen) if(retval) return retval; len = (len<<8) + (int)o; } + if (indef != NULL && !len) + *indef = 1; if(retlen != NULL) *retlen = len; } return 0; diff --git a/src/lib/krb5/asn.1/asn1_get.h b/src/lib/krb5/asn.1/asn1_get.h index f21c117db..2f5edf112 100644 --- a/src/lib/krb5/asn.1/asn1_get.h +++ b/src/lib/krb5/asn.1/asn1_get.h @@ -33,6 +33,12 @@ #include "krbasn1.h" #include "asn1buf.h" +asn1_error_code asn1_get_tag_indef + PROTOTYPE((asn1buf *buf, + asn1_class *class, + asn1_construction *construction, + asn1_tagnum *tagnum, + int *retlen, int *indef)); asn1_error_code asn1_get_tag PROTOTYPE((asn1buf *buf, asn1_class *class, @@ -49,7 +55,7 @@ asn1_error_code asn1_get_tag Returns ASN1_OVERRUN if *buf is exhausted during the parse. */ asn1_error_code asn1_get_sequence - PROTOTYPE((asn1buf *buf, int *retlen)); + PROTOTYPE((asn1buf *buf, int *retlen, int *indef)); /* requires *buf is allocated effects Decodes a tag from *buf and returns ASN1_BAD_ID if it doesn't have a sequence ID. If retlen != NULL, the @@ -71,7 +77,7 @@ asn1_error_code asn1_get_id Returns ASN1_OVERRUN if *buf is exhausted. */ asn1_error_code asn1_get_length - PROTOTYPE((asn1buf *buf, int *retlen)); + PROTOTYPE((asn1buf *buf, int *retlen, int *indef)); /* requires *buf is allocated effects Decodes the group of length octets at *buf's current position. If retlen != NULL, the diff --git a/src/lib/krb5/asn.1/asn1_k_decode.c b/src/lib/krb5/asn.1/asn1_k_decode.c index a92621a75..0c14e94f0 100644 --- a/src/lib/krb5/asn.1/asn1_k_decode.c +++ b/src/lib/krb5/asn.1/asn1_k_decode.c @@ -92,11 +92,10 @@ else { len = 0; var = 0; } #define begin_structure()\ asn1buf subbuf;\ -retval = asn1_get_tag(buf,&class,&construction,&tagnum,&length);\ +int indef;\ +retval = asn1_get_sequence(buf,&length,&indef);\ if(retval) return retval;\ -if(class != UNIVERSAL || construction != CONSTRUCTED ||\ - tagnum != ASN1_SEQUENCE) return ASN1_BAD_ID;\ -retval = asn1buf_imbed(&subbuf,buf,length);\ +retval = asn1buf_imbed(&subbuf,buf,length,indef);\ if(retval) return retval;\ next_tag() @@ -108,9 +107,10 @@ if(retval) return retval int size=0;\ asn1buf seqbuf;\ int length;\ -retval = asn1_get_sequence(buf,&length);\ +int indef;\ +retval = asn1_get_sequence(buf,&length,&indef);\ if(retval) return retval;\ -retval = asn1buf_imbed(&seqbuf,buf,length);\ +retval = asn1buf_imbed(&seqbuf,buf,length,indef);\ if(retval) return retval #define end_sequence_of(buf)\ diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c index 6d7a950b9..9c639279a 100644 --- a/src/lib/krb5/asn.1/asn1buf.c +++ b/src/lib/krb5/asn.1/asn1buf.c @@ -75,13 +75,14 @@ asn1_error_code asn1buf_wrap_data(buf, code) return 0; } -asn1_error_code asn1buf_imbed(subbuf, buf, length) +asn1_error_code asn1buf_imbed(subbuf, buf, length, indef) asn1buf * subbuf; const asn1buf * buf; const int length; + const int indef; { subbuf->base = subbuf->next = buf->next; - if (length > 0 ) { + if (!indef) { subbuf->bound = subbuf->base + length - 1; if (subbuf->bound > buf->bound) return ASN1_OVERRUN; diff --git a/src/lib/krb5/asn.1/asn1buf.h b/src/lib/krb5/asn.1/asn1buf.h index b1da42f7d..52fc0d625 100644 --- a/src/lib/krb5/asn.1/asn1buf.h +++ b/src/lib/krb5/asn.1/asn1buf.h @@ -111,7 +111,8 @@ asn1_error_code asn1buf_wrap_data Returns ASN1_MISSING_FIELD if code is empty. */ asn1_error_code asn1buf_imbed - PROTOTYPE((asn1buf *subbuf, const asn1buf *buf, const int length)); + PROTOTYPE((asn1buf *subbuf, const asn1buf *buf, const int length, + const int indef)); /* requires *subbuf and *buf are allocated effects *subbuf becomes a sub-buffer of *buf. *subbuf begins at *buf's current position and is length octets long. diff --git a/src/lib/krb5/asn.1/krb5_decode.c b/src/lib/krb5/asn.1/krb5_decode.c index d66f697c7..a56a1f451 100644 --- a/src/lib/krb5/asn.1/krb5_decode.c +++ b/src/lib/krb5/asn.1/krb5_decode.c @@ -85,11 +85,10 @@ if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ /* decode sequence header and initialize tagnum with the first field */ #define begin_structure()\ asn1buf subbuf;\ -retval = asn1_get_tag(&buf,&class,&construction,&tagnum,&length);\ +int indef;\ +retval = asn1_get_sequence(&buf,&length,&indef);\ if(retval) clean_return(retval);\ -if(class != UNIVERSAL || construction != CONSTRUCTED ||\ - tagnum != ASN1_SEQUENCE) clean_return(ASN1_BAD_ID);\ -retval = asn1buf_imbed(&subbuf,&buf,length);\ +retval = asn1buf_imbed(&subbuf,&buf,length,indef);\ if(retval) clean_return(retval);\ next_tag() -- cgit