From 4a567aecd188b56f8536be5bc0aa2aa41d171de4 Mon Sep 17 00:00:00 2001 From: Fabio Fiorina Date: Wed, 19 Mar 2003 22:07:34 +0000 Subject: [PATCH] change asn1_find_structure_from_oid prototype --- lib/coding.c | 14 +++++++------- tests/Test_tree.asn | 7 +++++++ tests/Test_tree.c | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/coding.c b/lib/coding.c index ea21141..a4e307f 100644 --- a/lib/coding.c +++ b/lib/coding.c @@ -175,9 +175,9 @@ _asn1_time_der(unsigned char *str,unsigned char *der,int *der_len) max_len=*der_len; - if(der==NULL) return ASN1_SUCCESS; - _asn1_length_der(strlen(str),der,&len_len); - if((len_len+strlen(str))<=max_len) + _asn1_length_der(strlen(str),(max_len>0)?der:NULL,&len_len); + + if((len_len+(int)strlen(str))<=max_len) memcpy(der+len_len,str,strlen(str)); *der_len=len_len+strlen(str); @@ -244,11 +244,10 @@ _asn1_objectid_der(unsigned char *str,unsigned char *der,int *der_len) unsigned char bit7; unsigned long val,val1=0; - if(der==NULL) return ASN1_SUCCESS; - max_len=*der_len; - temp=(char *) malloc(strlen(str)+2); + temp=(char *) _asn1_alloca(strlen(str)+2); + if(temp==NULL) return ASN1_MEM_ALLOC_ERROR; strcpy(temp, str); strcat(temp, "."); @@ -290,7 +289,7 @@ _asn1_objectid_der(unsigned char *str,unsigned char *der,int *der_len) } *der_len+=len_len; - free(temp); + _asn1_afree(temp); if(max_len<(*der_len)) return ASN1_MEM_ERROR; @@ -812,6 +811,7 @@ asn1_der_coding(ASN1_TYPE element,const char *name,unsigned char *der,int *len, } len2=max_len; ris=_asn1_objectid_der(p->value,der+counter,&len2); + if(ris==ASN1_MEM_ALLOC_ERROR) return ris; max_len-=len2; counter+=len2; move=RIGHT; diff --git a/tests/Test_tree.asn b/tests/Test_tree.asn index bd25fc7..e0d0063 100644 --- a/tests/Test_tree.asn +++ b/tests/Test_tree.asn @@ -9,6 +9,13 @@ DEFINITIONS IMPLICIT TAGS ::= BEGIN +OidAndTimeTest ::= SEQUENCE{ + oid OBJECT IDENTIFIER, + time1 UTCTime, + time2 GeneralizedTime, + oct OCTET STRING +} + SequenceTestTag ::= SEQUENCE{ int1 [2] EXPLICIT INTEGER, int2 [3] IMPLICIT INTEGER, diff --git a/tests/Test_tree.c b/tests/Test_tree.c index 6b75139..9d165b9 100644 --- a/tests/Test_tree.c +++ b/tests/Test_tree.c @@ -69,6 +69,26 @@ test_type test_array[]={ {ACT_DELETE,"","",0,ASN1_ELEMENT_NOT_FOUND}, + /* Test: OID and TIME */ + {ACT_CREATE,"TEST_TREE.OidAndTimeTest",0,0,ASN1_SUCCESS}, + {ACT_WRITE,"oid","1.2.3.4",0,ASN1_SUCCESS}, + {ACT_WRITE,"time1","9801011200Z",1,ASN1_SUCCESS}, + {ACT_WRITE,"time2","2001010112001.12-0700",1,ASN1_SUCCESS}, + {ACT_WRITE,"oct","ABCD",4,ASN1_SUCCESS}, + {ACT_READ_LENGTH,"oid",NULL,8,ASN1_MEM_ERROR}, + {ACT_READ_LENGTH,"time1",NULL,12,ASN1_MEM_ERROR}, + {ACT_READ_LENGTH,"time2",NULL,22,ASN1_MEM_ERROR}, + {ACT_READ_LENGTH,"oct",NULL,4,ASN1_MEM_ERROR}, + {ACT_ENCODING_LENGTH,"",0,49,ASN1_MEM_ERROR}, + {ACT_ENCODING,"",0,48,ASN1_MEM_ERROR}, + {ACT_ENCODING,"",0,200,ASN1_SUCCESS}, + {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS}, + {ACT_DELETE,"","",0,ASN1_SUCCESS}, + {ACT_CREATE,"TEST_TREE.OidAndTimeTest",0,0,ASN1_SUCCESS}, + {ACT_DECODING,0,0,0,ASN1_SUCCESS}, + {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS}, + {ACT_DELETE,"","",0,ASN1_SUCCESS}, + /* Test: OID to STRUCTURE */ {ACT_OID_2_STRUCTURE,"2.5.29.3","",0,ASN1_ELEMENT_NOT_FOUND}, {ACT_OID_2_STRUCTURE,"1.2.29.2","",0,ASN1_ELEMENT_NOT_FOUND}, -- 2.7.4