diff options
| author | beck <> | 2000-12-15 02:58:47 +0000 |
|---|---|---|
| committer | beck <> | 2000-12-15 02:58:47 +0000 |
| commit | 9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch) | |
| tree | 5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/asn1/a_object.c | |
| parent | e131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff) | |
| download | openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2 openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip | |
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/asn1/a_object.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_object.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 09d56fb669..20caa2d3bd 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
| @@ -65,11 +65,12 @@ | |||
| 65 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | 65 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) |
| 66 | { | 66 | { |
| 67 | unsigned char *p; | 67 | unsigned char *p; |
| 68 | int objsize; | ||
| 68 | 69 | ||
| 69 | if ((a == NULL) || (a->data == NULL)) return(0); | 70 | if ((a == NULL) || (a->data == NULL)) return(0); |
| 70 | 71 | ||
| 71 | if (pp == NULL) | 72 | objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); |
| 72 | return(ASN1_object_size(0,a->length,V_ASN1_OBJECT)); | 73 | if (pp == NULL) return objsize; |
| 73 | 74 | ||
| 74 | p= *pp; | 75 | p= *pp; |
| 75 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | 76 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); |
| @@ -77,7 +78,7 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | |||
| 77 | p+=a->length; | 78 | p+=a->length; |
| 78 | 79 | ||
| 79 | *pp=p; | 80 | *pp=p; |
| 80 | return(a->length); | 81 | return(objsize); |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | 84 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) |
| @@ -190,24 +191,13 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | |||
| 190 | 191 | ||
| 191 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | 192 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, |
| 192 | long length) | 193 | long length) |
| 193 | { | 194 | { |
| 194 | ASN1_OBJECT *ret=NULL; | ||
| 195 | unsigned char *p; | 195 | unsigned char *p; |
| 196 | long len; | 196 | long len; |
| 197 | int tag,xclass; | 197 | int tag,xclass; |
| 198 | int inf,i; | 198 | int inf,i; |
| 199 | 199 | ASN1_OBJECT *ret = NULL; | |
| 200 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
| 201 | * for ->sn or ->ln */ | ||
| 202 | if ((a == NULL) || ((*a) == NULL) || | ||
| 203 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 204 | { | ||
| 205 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
| 206 | } | ||
| 207 | else ret=(*a); | ||
| 208 | |||
| 209 | p= *pp; | 200 | p= *pp; |
| 210 | |||
| 211 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | 201 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); |
| 212 | if (inf & 0x80) | 202 | if (inf & 0x80) |
| 213 | { | 203 | { |
| @@ -220,10 +210,36 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | |||
| 220 | i=ASN1_R_EXPECTING_AN_OBJECT; | 210 | i=ASN1_R_EXPECTING_AN_OBJECT; |
| 221 | goto err; | 211 | goto err; |
| 222 | } | 212 | } |
| 213 | ret = c2i_ASN1_OBJECT(a, &p, len); | ||
| 214 | if(ret) *pp = p; | ||
| 215 | return ret; | ||
| 216 | err: | ||
| 217 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | ||
| 218 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 219 | ASN1_OBJECT_free(ret); | ||
| 220 | return(NULL); | ||
| 221 | } | ||
| 222 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | ||
| 223 | long len) | ||
| 224 | { | ||
| 225 | ASN1_OBJECT *ret=NULL; | ||
| 226 | unsigned char *p; | ||
| 227 | int i; | ||
| 228 | |||
| 229 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
| 230 | * for ->sn or ->ln */ | ||
| 231 | if ((a == NULL) || ((*a) == NULL) || | ||
| 232 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 233 | { | ||
| 234 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
| 235 | } | ||
| 236 | else ret=(*a); | ||
| 237 | |||
| 238 | p= *pp; | ||
| 223 | if ((ret->data == NULL) || (ret->length < len)) | 239 | if ((ret->data == NULL) || (ret->length < len)) |
| 224 | { | 240 | { |
| 225 | if (ret->data != NULL) Free(ret->data); | 241 | if (ret->data != NULL) OPENSSL_free(ret->data); |
| 226 | ret->data=(unsigned char *)Malloc(len ? (int)len : 1); | 242 | ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1); |
| 227 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | 243 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; |
| 228 | if (ret->data == NULL) | 244 | if (ret->data == NULL) |
| 229 | { i=ERR_R_MALLOC_FAILURE; goto err; } | 245 | { i=ERR_R_MALLOC_FAILURE; goto err; } |
| @@ -249,7 +265,7 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) | |||
| 249 | { | 265 | { |
| 250 | ASN1_OBJECT *ret; | 266 | ASN1_OBJECT *ret; |
| 251 | 267 | ||
| 252 | ret=(ASN1_OBJECT *)Malloc(sizeof(ASN1_OBJECT)); | 268 | ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT)); |
| 253 | if (ret == NULL) | 269 | if (ret == NULL) |
| 254 | { | 270 | { |
| 255 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | 271 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); |
| @@ -270,19 +286,19 @@ void ASN1_OBJECT_free(ASN1_OBJECT *a) | |||
| 270 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | 286 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) |
| 271 | { | 287 | { |
| 272 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ | 288 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ |
| 273 | if (a->sn != NULL) Free((void *)a->sn); | 289 | if (a->sn != NULL) OPENSSL_free((void *)a->sn); |
| 274 | if (a->ln != NULL) Free((void *)a->ln); | 290 | if (a->ln != NULL) OPENSSL_free((void *)a->ln); |
| 275 | #endif | 291 | #endif |
| 276 | a->sn=a->ln=NULL; | 292 | a->sn=a->ln=NULL; |
| 277 | } | 293 | } |
| 278 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | 294 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) |
| 279 | { | 295 | { |
| 280 | if (a->data != NULL) Free(a->data); | 296 | if (a->data != NULL) OPENSSL_free(a->data); |
| 281 | a->data=NULL; | 297 | a->data=NULL; |
| 282 | a->length=0; | 298 | a->length=0; |
| 283 | } | 299 | } |
| 284 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | 300 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) |
| 285 | Free(a); | 301 | OPENSSL_free(a); |
| 286 | } | 302 | } |
| 287 | 303 | ||
| 288 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | 304 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, |
