OLD | NEW |
1 /* crypto/objects/obj_lib.c */ | 1 /* crypto/objects/obj_lib.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include <stdio.h> | 59 #include <stdio.h> |
60 #include "cryptlib.h" | 60 #include "cryptlib.h" |
61 #include <openssl/lhash.h> | 61 #include <openssl/lhash.h> |
62 #include <openssl/objects.h> | 62 #include <openssl/objects.h> |
63 #include <openssl/buffer.h> | 63 #include <openssl/buffer.h> |
64 | 64 |
65 ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) | 65 ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) |
66 { | 66 { |
67 ASN1_OBJECT *r; | 67 ASN1_OBJECT *r; |
68 int i; | 68 int i; |
69 » char *ln=NULL; | 69 » char *ln=NULL,*sn=NULL; |
| 70 » unsigned char *data=NULL; |
70 | 71 |
71 if (o == NULL) return(NULL); | 72 if (o == NULL) return(NULL); |
72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | 73 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) |
73 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of | 74 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of |
74 duplication is this??? */ | 75 duplication is this??? */ |
75 | 76 |
76 r=ASN1_OBJECT_new(); | 77 r=ASN1_OBJECT_new(); |
77 if (r == NULL) | 78 if (r == NULL) |
78 { | 79 { |
79 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); | 80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); |
80 return(NULL); | 81 return(NULL); |
81 } | 82 } |
82 » r->data=OPENSSL_malloc(o->length); | 83 » data=OPENSSL_malloc(o->length); |
83 » if (r->data == NULL) | 84 » if (data == NULL) |
84 goto err; | 85 goto err; |
85 if (o->data != NULL) | 86 if (o->data != NULL) |
86 » » memcpy(r->data,o->data,o->length); | 87 » » memcpy(data,o->data,o->length); |
| 88 » /* once data attached to object it remains const */ |
| 89 » r->data = data; |
87 r->length=o->length; | 90 r->length=o->length; |
88 r->nid=o->nid; | 91 r->nid=o->nid; |
89 r->ln=r->sn=NULL; | 92 r->ln=r->sn=NULL; |
90 if (o->ln != NULL) | 93 if (o->ln != NULL) |
91 { | 94 { |
92 i=strlen(o->ln)+1; | 95 i=strlen(o->ln)+1; |
93 » » r->ln=ln=OPENSSL_malloc(i); | 96 » » ln=OPENSSL_malloc(i); |
94 » » if (r->ln == NULL) goto err; | 97 » » if (ln == NULL) goto err; |
95 memcpy(ln,o->ln,i); | 98 memcpy(ln,o->ln,i); |
| 99 r->ln=ln; |
96 } | 100 } |
97 | 101 |
98 if (o->sn != NULL) | 102 if (o->sn != NULL) |
99 { | 103 { |
100 char *s; | |
101 | |
102 i=strlen(o->sn)+1; | 104 i=strlen(o->sn)+1; |
103 » » r->sn=s=OPENSSL_malloc(i); | 105 » » sn=OPENSSL_malloc(i); |
104 » » if (r->sn == NULL) goto err; | 106 » » if (sn == NULL) goto err; |
105 » » memcpy(s,o->sn,i); | 107 » » memcpy(sn,o->sn,i); |
| 108 » » r->sn=sn; |
106 } | 109 } |
107 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC| | 110 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC| |
108 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA); | 111 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA); |
109 return(r); | 112 return(r); |
110 err: | 113 err: |
111 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); | 114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); |
112 » if (r != NULL) | 115 » if (ln != NULL)»» OPENSSL_free(ln); |
113 » » { | 116 » if (sn != NULL)»» OPENSSL_free(sn); |
114 » » if (ln != NULL) OPENSSL_free(ln); | 117 » if (data != NULL)» OPENSSL_free(data); |
115 » » if (r->data != NULL) OPENSSL_free(r->data); | 118 » if (r != NULL)» » OPENSSL_free(r); |
116 » » OPENSSL_free(r); | |
117 » » } | |
118 return(NULL); | 119 return(NULL); |
119 } | 120 } |
120 | 121 |
121 int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b) | 122 int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b) |
122 { | 123 { |
123 int ret; | 124 int ret; |
124 | 125 |
125 ret=(a->length-b->length); | 126 ret=(a->length-b->length); |
126 if (ret) return(ret); | 127 if (ret) return(ret); |
127 return(memcmp(a->data,b->data,a->length)); | 128 return(memcmp(a->data,b->data,a->length)); |
128 } | 129 } |
OLD | NEW |