~ubuntu-branches/ubuntu/hardy/openssl/hardy-security

« back to all changes in this revision

Viewing changes to crypto/asn1/tasn_fre.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051213213742-7em5nrw5c7ceegyd
Tags: 0.9.8a-5
Stop ssh from crashing randomly on sparc (Closes: #335912)
Patch from upstream cvs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
/* Free up an ASN1 structure */
68
68
 
69
69
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
70
 
{
 
70
        {
71
71
        asn1_item_combine_free(&val, it, 0);
72
 
}
 
72
        }
73
73
 
74
74
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
75
 
{
 
75
        {
76
76
        asn1_item_combine_free(pval, it, 0);
77
 
}
 
77
        }
78
78
 
79
79
static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
80
 
{
 
80
        {
81
81
        const ASN1_TEMPLATE *tt = NULL, *seqtt;
82
82
        const ASN1_EXTERN_FUNCS *ef;
83
83
        const ASN1_COMPAT_FUNCS *cf;
84
84
        const ASN1_AUX *aux = it->funcs;
85
85
        ASN1_aux_cb *asn1_cb;
86
86
        int i;
87
 
        if(!pval) return;
88
 
        if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
89
 
        if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
90
 
        else asn1_cb = 0;
 
87
        if (!pval)
 
88
                return;
 
89
        if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
 
90
                return;
 
91
        if (aux && aux->asn1_cb)
 
92
                asn1_cb = aux->asn1_cb;
 
93
        else
 
94
                asn1_cb = 0;
91
95
 
92
 
        switch(it->itype) {
 
96
        switch(it->itype)
 
97
                {
93
98
 
94
99
                case ASN1_ITYPE_PRIMITIVE:
95
 
                if(it->templates) ASN1_template_free(pval, it->templates);
96
 
                else ASN1_primitive_free(pval, it);
 
100
                if (it->templates)
 
101
                        ASN1_template_free(pval, it->templates);
 
102
                else
 
103
                        ASN1_primitive_free(pval, it);
97
104
                break;
98
105
 
99
106
                case ASN1_ITYPE_MSTRING:
101
108
                break;
102
109
 
103
110
                case ASN1_ITYPE_CHOICE:
104
 
                if(asn1_cb) {
 
111
                if (asn1_cb)
 
112
                        {
105
113
                        i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
106
 
                        if(i == 2) return;
107
 
                }
 
114
                        if (i == 2)
 
115
                                return;
 
116
                        }
108
117
                i = asn1_get_choice_selector(pval, it);
109
 
                if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
110
 
                if((i >= 0) && (i < it->tcount)) {
 
118
                if (asn1_cb)
 
119
                        asn1_cb(ASN1_OP_FREE_PRE, pval, it);
 
120
                if ((i >= 0) && (i < it->tcount))
 
121
                        {
111
122
                        ASN1_VALUE **pchval;
112
123
                        tt = it->templates + i;
113
124
                        pchval = asn1_get_field_ptr(pval, tt);
114
125
                        ASN1_template_free(pchval, tt);
115
 
                }
116
 
                if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
117
 
                if(!combine) {
 
126
                        }
 
127
                if (asn1_cb)
 
128
                        asn1_cb(ASN1_OP_FREE_POST, pval, it);
 
129
                if (!combine)
 
130
                        {
118
131
                        OPENSSL_free(*pval);
119
132
                        *pval = NULL;
120
 
                }
 
133
                        }
121
134
                break;
122
135
 
123
136
                case ASN1_ITYPE_COMPAT:
124
137
                cf = it->funcs;
125
 
                if(cf && cf->asn1_free) cf->asn1_free(*pval);
 
138
                if (cf && cf->asn1_free)
 
139
                        cf->asn1_free(*pval);
126
140
                break;
127
141
 
128
142
                case ASN1_ITYPE_EXTERN:
129
143
                ef = it->funcs;
130
 
                if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
 
144
                if (ef && ef->asn1_ex_free)
 
145
                        ef->asn1_ex_free(pval, it);
131
146
                break;
132
147
 
 
148
                case ASN1_ITYPE_NDEF_SEQUENCE:
133
149
                case ASN1_ITYPE_SEQUENCE:
134
 
                if(asn1_do_lock(pval, -1, it) > 0) return;
135
 
                if(asn1_cb) {
 
150
                if (asn1_do_lock(pval, -1, it) > 0)
 
151
                        return;
 
152
                if (asn1_cb)
 
153
                        {
136
154
                        i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
137
 
                        if(i == 2) return;
138
 
                }               
 
155
                        if (i == 2)
 
156
                                return;
 
157
                        }               
139
158
                asn1_enc_free(pval, it);
140
159
                /* If we free up as normal we will invalidate any
141
160
                 * ANY DEFINED BY field and we wont be able to 
143
162
                 * free up in reverse order.
144
163
                 */
145
164
                tt = it->templates + it->tcount - 1;
146
 
                for(i = 0; i < it->tcount; tt--, i++) {
 
165
                for (i = 0; i < it->tcount; tt--, i++)
 
166
                        {
147
167
                        ASN1_VALUE **pseqval;
148
168
                        seqtt = asn1_do_adb(pval, tt, 0);
149
 
                        if(!seqtt) continue;
 
169
                        if (!seqtt)
 
170
                                continue;
150
171
                        pseqval = asn1_get_field_ptr(pval, seqtt);
151
172
                        ASN1_template_free(pseqval, seqtt);
152
 
                }
153
 
                if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
154
 
                if(!combine) {
 
173
                        }
 
174
                if (asn1_cb)
 
175
                        asn1_cb(ASN1_OP_FREE_POST, pval, it);
 
176
                if (!combine)
 
177
                        {
155
178
                        OPENSSL_free(*pval);
156
179
                        *pval = NULL;
157
 
                }
 
180
                        }
158
181
                break;
 
182
                }
159
183
        }
160
 
}
161
184
 
162
185
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
163
 
{
 
186
        {
164
187
        int i;
165
 
        if(tt->flags & ASN1_TFLG_SK_MASK) {
 
188
        if (tt->flags & ASN1_TFLG_SK_MASK)
 
189
                {
166
190
                STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
167
 
                for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
 
191
                for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
 
192
                        {
168
193
                        ASN1_VALUE *vtmp;
169
194
                        vtmp = sk_ASN1_VALUE_value(sk, i);
170
 
                        asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
171
 
                }
 
195
                        asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item),
 
196
                                                                        0);
 
197
                        }
172
198
                sk_ASN1_VALUE_free(sk);
173
199
                *pval = NULL;
174
 
        } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
 
200
                }
 
201
        else
 
202
                asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
175
203
                                                tt->flags & ASN1_TFLG_COMBINE);
176
 
}
 
204
        }
177
205
 
178
206
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
179
 
{
 
207
        {
180
208
        int utype;
181
 
        if(it) {
 
209
        if (it)
 
210
                {
182
211
                const ASN1_PRIMITIVE_FUNCS *pf;
183
212
                pf = it->funcs;
184
 
                if(pf && pf->prim_free) {
 
213
                if (pf && pf->prim_free)
 
214
                        {
185
215
                        pf->prim_free(pval, it);
186
216
                        return;
 
217
                        }
187
218
                }
188
 
        }
189
219
        /* Special case: if 'it' is NULL free contents of ASN1_TYPE */
190
 
        if(!it) {
 
220
        if (!it)
 
221
                {
191
222
                ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
192
223
                utype = typ->type;
193
224
                pval = (ASN1_VALUE **)&typ->value.ptr;
194
 
                if(!*pval) return;
195
 
        } else if(it->itype == ASN1_ITYPE_MSTRING) {
 
225
                if (!*pval)
 
226
                        return;
 
227
                }
 
228
        else if (it->itype == ASN1_ITYPE_MSTRING)
 
229
                {
196
230
                utype = -1;
197
 
                if(!*pval) return;
198
 
        } else {
 
231
                if (!*pval)
 
232
                        return;
 
233
                }
 
234
        else
 
235
                {
199
236
                utype = it->utype;
200
 
                if((utype != V_ASN1_BOOLEAN) && !*pval) return;
201
 
        }
 
237
                if ((utype != V_ASN1_BOOLEAN) && !*pval)
 
238
                        return;
 
239
                }
202
240
 
203
 
        switch(utype) {
 
241
        switch(utype)
 
242
                {
204
243
                case V_ASN1_OBJECT:
205
244
                ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
206
245
                break;
224
263
                ASN1_STRING_free((ASN1_STRING *)*pval);
225
264
                *pval = NULL;
226
265
                break;
227
 
        }
 
266
                }
228
267
        *pval = NULL;
229
 
}
 
268
        }