Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_object.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||
2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||||||||
3 | * | - | ||||||||||||||||||||||||
4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||||||||
5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||||||||
6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||||||||
7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||||||||
8 | */ | - | ||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||
10 | #include <stdio.h> | - | ||||||||||||||||||||||||
11 | #include <limits.h> | - | ||||||||||||||||||||||||
12 | #include "internal/ctype.h" | - | ||||||||||||||||||||||||
13 | #include "internal/cryptlib.h" | - | ||||||||||||||||||||||||
14 | #include <openssl/buffer.h> | - | ||||||||||||||||||||||||
15 | #include <openssl/asn1.h> | - | ||||||||||||||||||||||||
16 | #include <openssl/objects.h> | - | ||||||||||||||||||||||||
17 | #include <openssl/bn.h> | - | ||||||||||||||||||||||||
18 | #include "internal/asn1_int.h" | - | ||||||||||||||||||||||||
19 | #include "asn1_locl.h" | - | ||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp) | - | ||||||||||||||||||||||||
22 | { | - | ||||||||||||||||||||||||
23 | unsigned char *p, *allocated = NULL; | - | ||||||||||||||||||||||||
24 | int objsize; | - | ||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||
26 | if ((a == NULL) || (a->data == NULL))
| 0 | ||||||||||||||||||||||||
27 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT); | - | ||||||||||||||||||||||||
30 | if (pp == NULL || objsize == -1)
| 0 | ||||||||||||||||||||||||
31 | return objsize; never executed: return objsize; | 0 | ||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | if (*pp == NULL) {
| 0 | ||||||||||||||||||||||||
34 | if ((p = allocated = OPENSSL_malloc(objsize)) == NULL) {
| 0 | ||||||||||||||||||||||||
35 | ASN1err(ASN1_F_I2D_ASN1_OBJECT, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
36 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
37 | } | - | ||||||||||||||||||||||||
38 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
39 | p = *pp; | - | ||||||||||||||||||||||||
40 | } never executed: end of block | 0 | ||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | ASN1_put_object(&p, 0, a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL); | - | ||||||||||||||||||||||||
43 | memcpy(p, a->data, a->length); | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | /* | - | ||||||||||||||||||||||||
46 | * If a new buffer was allocated, just return it back. | - | ||||||||||||||||||||||||
47 | * If not, return the incremented buffer pointer. | - | ||||||||||||||||||||||||
48 | */ | - | ||||||||||||||||||||||||
49 | *pp = allocated != NULL ? allocated : p + a->length;
| 0 | ||||||||||||||||||||||||
50 | return objsize; never executed: return objsize; | 0 | ||||||||||||||||||||||||
51 | } | - | ||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||
53 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | - | ||||||||||||||||||||||||
54 | { | - | ||||||||||||||||||||||||
55 | int i, first, len = 0, c, use_bn; | - | ||||||||||||||||||||||||
56 | char ftmp[24], *tmp = ftmp; | - | ||||||||||||||||||||||||
57 | int tmpsize = sizeof(ftmp); | - | ||||||||||||||||||||||||
58 | const char *p; | - | ||||||||||||||||||||||||
59 | unsigned long l; | - | ||||||||||||||||||||||||
60 | BIGNUM *bl = NULL; | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | if (num == 0)
| 0-190 | ||||||||||||||||||||||||
63 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
64 | else if (num == -1)
| 0-190 | ||||||||||||||||||||||||
65 | num = strlen(buf); executed 190 times by 1 test: num = strlen(buf); Executed by:
| 190 | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | p = buf; | - | ||||||||||||||||||||||||
68 | c = *(p++); | - | ||||||||||||||||||||||||
69 | num--; | - | ||||||||||||||||||||||||
70 | if ((c >= '0') && (c <= '2')) {
| 0-190 | ||||||||||||||||||||||||
71 | first = c - '0'; | - | ||||||||||||||||||||||||
72 | } else { executed 190 times by 1 test: end of block Executed by:
| 190 | ||||||||||||||||||||||||
73 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE); | - | ||||||||||||||||||||||||
74 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
75 | } | - | ||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||
77 | if (num <= 0) {
| 0-190 | ||||||||||||||||||||||||
78 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER); | - | ||||||||||||||||||||||||
79 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
80 | } | - | ||||||||||||||||||||||||
81 | c = *(p++); | - | ||||||||||||||||||||||||
82 | num--; | - | ||||||||||||||||||||||||
83 | for (;;) { | - | ||||||||||||||||||||||||
84 | if (num <= 0)
| 190-652 | ||||||||||||||||||||||||
85 | break; executed 190 times by 1 test: break; Executed by:
| 190 | ||||||||||||||||||||||||
86 | if ((c != '.') && (c != ' ')) {
| 0-652 | ||||||||||||||||||||||||
87 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_SEPARATOR); | - | ||||||||||||||||||||||||
88 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
89 | } | - | ||||||||||||||||||||||||
90 | l = 0; | - | ||||||||||||||||||||||||
91 | use_bn = 0; | - | ||||||||||||||||||||||||
92 | for (;;) { | - | ||||||||||||||||||||||||
93 | if (num <= 0)
| 190-1466 | ||||||||||||||||||||||||
94 | break; executed 190 times by 1 test: break; Executed by:
| 190 | ||||||||||||||||||||||||
95 | num--; | - | ||||||||||||||||||||||||
96 | c = *(p++); | - | ||||||||||||||||||||||||
97 | if ((c == ' ') || (c == '.'))
| 0-1466 | ||||||||||||||||||||||||
98 | break; executed 462 times by 1 test: break; Executed by:
| 462 | ||||||||||||||||||||||||
99 | if (!ossl_isdigit(c)) {
| 0-1004 | ||||||||||||||||||||||||
100 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_DIGIT); | - | ||||||||||||||||||||||||
101 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
102 | } | - | ||||||||||||||||||||||||
103 | if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
| 0-1004 | ||||||||||||||||||||||||
104 | use_bn = 1; | - | ||||||||||||||||||||||||
105 | if (bl == NULL)
| 0 | ||||||||||||||||||||||||
106 | bl = BN_new(); never executed: bl = BN_new(); | 0 | ||||||||||||||||||||||||
107 | if (bl == NULL || !BN_set_word(bl, l))
| 0 | ||||||||||||||||||||||||
108 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
109 | } never executed: end of block | 0 | ||||||||||||||||||||||||
110 | if (use_bn) {
| 0-1004 | ||||||||||||||||||||||||
111 | if (!BN_mul_word(bl, 10L)
| 0 | ||||||||||||||||||||||||
112 | || !BN_add_word(bl, c - '0'))
| 0 | ||||||||||||||||||||||||
113 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
114 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
115 | l = l * 10L + (long)(c - '0'); executed 1004 times by 1 test: l = l * 10L + (long)(c - '0'); Executed by:
| 1004 | ||||||||||||||||||||||||
116 | } | - | ||||||||||||||||||||||||
117 | if (len == 0) {
| 190-462 | ||||||||||||||||||||||||
118 | if ((first < 2) && (l >= 40)) {
| 0-102 | ||||||||||||||||||||||||
119 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, | - | ||||||||||||||||||||||||
120 | ASN1_R_SECOND_NUMBER_TOO_LARGE); | - | ||||||||||||||||||||||||
121 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
122 | } | - | ||||||||||||||||||||||||
123 | if (use_bn) {
| 0-190 | ||||||||||||||||||||||||
124 | if (!BN_add_word(bl, first * 40))
| 0 | ||||||||||||||||||||||||
125 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
126 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
127 | l += (long)first *40; executed 190 times by 1 test: l += (long)first *40; Executed by:
| 190 | ||||||||||||||||||||||||
128 | } | - | ||||||||||||||||||||||||
129 | i = 0; | - | ||||||||||||||||||||||||
130 | if (use_bn) {
| 0-652 | ||||||||||||||||||||||||
131 | int blsize; | - | ||||||||||||||||||||||||
132 | blsize = BN_num_bits(bl); | - | ||||||||||||||||||||||||
133 | blsize = (blsize + 6) / 7; | - | ||||||||||||||||||||||||
134 | if (blsize > tmpsize) {
| 0 | ||||||||||||||||||||||||
135 | if (tmp != ftmp)
| 0 | ||||||||||||||||||||||||
136 | OPENSSL_free(tmp); never executed: CRYPTO_free(tmp, __FILE__, 136); | 0 | ||||||||||||||||||||||||
137 | tmpsize = blsize + 32; | - | ||||||||||||||||||||||||
138 | tmp = OPENSSL_malloc(tmpsize); | - | ||||||||||||||||||||||||
139 | if (tmp == NULL)
| 0 | ||||||||||||||||||||||||
140 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
141 | } never executed: end of block | 0 | ||||||||||||||||||||||||
142 | while (blsize--) {
| 0 | ||||||||||||||||||||||||
143 | BN_ULONG t = BN_div_word(bl, 0x80L); | - | ||||||||||||||||||||||||
144 | if (t == (BN_ULONG)-1)
| 0 | ||||||||||||||||||||||||
145 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
146 | tmp[i++] = (unsigned char)t; | - | ||||||||||||||||||||||||
147 | } never executed: end of block | 0 | ||||||||||||||||||||||||
148 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | for (;;) { | - | ||||||||||||||||||||||||
151 | tmp[i++] = (unsigned char)l & 0x7f; | - | ||||||||||||||||||||||||
152 | l >>= 7L; | - | ||||||||||||||||||||||||
153 | if (l == 0L)
| 176-652 | ||||||||||||||||||||||||
154 | break; executed 652 times by 1 test: break; Executed by:
| 652 | ||||||||||||||||||||||||
155 | } executed 176 times by 1 test: end of block Executed by:
| 176 | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | } executed 652 times by 1 test: end of block Executed by:
| 652 | ||||||||||||||||||||||||
158 | if (out != NULL) {
| 326 | ||||||||||||||||||||||||
159 | if (len + i > olen) {
| 0-326 | ||||||||||||||||||||||||
160 | ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_BUFFER_TOO_SMALL); | - | ||||||||||||||||||||||||
161 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
162 | } | - | ||||||||||||||||||||||||
163 | while (--i > 0)
| 88-326 | ||||||||||||||||||||||||
164 | out[len++] = tmp[i] | 0x80; executed 88 times by 1 test: out[len++] = tmp[i] | 0x80; Executed by:
| 88 | ||||||||||||||||||||||||
165 | out[len++] = tmp[0]; | - | ||||||||||||||||||||||||
166 | } else executed 326 times by 1 test: end of block Executed by:
| 326 | ||||||||||||||||||||||||
167 | len += i; executed 326 times by 1 test: len += i; Executed by:
| 326 | ||||||||||||||||||||||||
168 | } | - | ||||||||||||||||||||||||
169 | if (tmp != ftmp)
| 0-190 | ||||||||||||||||||||||||
170 | OPENSSL_free(tmp); never executed: CRYPTO_free(tmp, __FILE__, 170); | 0 | ||||||||||||||||||||||||
171 | BN_free(bl); | - | ||||||||||||||||||||||||
172 | return len; executed 190 times by 1 test: return len; Executed by:
| 190 | ||||||||||||||||||||||||
173 | err: | - | ||||||||||||||||||||||||
174 | if (tmp != ftmp)
| 0 | ||||||||||||||||||||||||
175 | OPENSSL_free(tmp); never executed: CRYPTO_free(tmp, __FILE__, 175); | 0 | ||||||||||||||||||||||||
176 | BN_free(bl); | - | ||||||||||||||||||||||||
177 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
178 | } | - | ||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a) | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | return OBJ_obj2txt(buf, buf_len, a, 0); executed 347467 times by 1 test: return OBJ_obj2txt(buf, buf_len, a, 0); Executed by:
| 347467 | ||||||||||||||||||||||||
183 | } | - | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a) | - | ||||||||||||||||||||||||
186 | { | - | ||||||||||||||||||||||||
187 | char buf[80], *p = buf; | - | ||||||||||||||||||||||||
188 | int i; | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | if ((a == NULL) || (a->data == NULL))
| 0-333081 | ||||||||||||||||||||||||
191 | return BIO_write(bp, "NULL", 4); never executed: return BIO_write(bp, "NULL", 4); | 0 | ||||||||||||||||||||||||
192 | i = i2t_ASN1_OBJECT(buf, sizeof(buf), a); | - | ||||||||||||||||||||||||
193 | if (i > (int)(sizeof(buf) - 1)) {
| 1540-331541 | ||||||||||||||||||||||||
194 | if ((p = OPENSSL_malloc(i + 1)) == NULL) {
| 0-1540 | ||||||||||||||||||||||||
195 | ASN1err(ASN1_F_I2A_ASN1_OBJECT, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
196 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
197 | } | - | ||||||||||||||||||||||||
198 | i2t_ASN1_OBJECT(p, i + 1, a); | - | ||||||||||||||||||||||||
199 | } executed 1540 times by 1 test: end of block Executed by:
| 1540 | ||||||||||||||||||||||||
200 | if (i <= 0) {
| 0-333081 | ||||||||||||||||||||||||
201 | i = BIO_write(bp, "<INVALID>", 9); | - | ||||||||||||||||||||||||
202 | i += BIO_dump(bp, (const char *)a->data, a->length); | - | ||||||||||||||||||||||||
203 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||
204 | } | - | ||||||||||||||||||||||||
205 | BIO_write(bp, p, i); | - | ||||||||||||||||||||||||
206 | if (p != buf)
| 1540-331541 | ||||||||||||||||||||||||
207 | OPENSSL_free(p); executed 1540 times by 1 test: CRYPTO_free(p, __FILE__, 207); Executed by:
| 1540 | ||||||||||||||||||||||||
208 | return i; executed 333081 times by 1 test: return i; Executed by:
| 333081 | ||||||||||||||||||||||||
209 | } | - | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | - | ||||||||||||||||||||||||
212 | long length) | - | ||||||||||||||||||||||||
213 | { | - | ||||||||||||||||||||||||
214 | const unsigned char *p; | - | ||||||||||||||||||||||||
215 | long len; | - | ||||||||||||||||||||||||
216 | int tag, xclass; | - | ||||||||||||||||||||||||
217 | int inf, i; | - | ||||||||||||||||||||||||
218 | ASN1_OBJECT *ret = NULL; | - | ||||||||||||||||||||||||
219 | p = *pp; | - | ||||||||||||||||||||||||
220 | inf = ASN1_get_object(&p, &len, &tag, &xclass, length); | - | ||||||||||||||||||||||||
221 | if (inf & 0x80) {
| 609-231476 | ||||||||||||||||||||||||
222 | i = ASN1_R_BAD_OBJECT_HEADER; | - | ||||||||||||||||||||||||
223 | goto err; executed 609 times by 1 test: goto err; Executed by:
| 609 | ||||||||||||||||||||||||
224 | } | - | ||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||
226 | if (tag != V_ASN1_OBJECT) {
| 0-231476 | ||||||||||||||||||||||||
227 | i = ASN1_R_EXPECTING_AN_OBJECT; | - | ||||||||||||||||||||||||
228 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
229 | } | - | ||||||||||||||||||||||||
230 | ret = c2i_ASN1_OBJECT(a, &p, len); | - | ||||||||||||||||||||||||
231 | if (ret)
| 8374-223102 | ||||||||||||||||||||||||
232 | *pp = p; executed 223102 times by 1 test: *pp = p; Executed by:
| 223102 | ||||||||||||||||||||||||
233 | return ret; executed 231476 times by 1 test: return ret; Executed by:
| 231476 | ||||||||||||||||||||||||
234 | err: | - | ||||||||||||||||||||||||
235 | ASN1err(ASN1_F_D2I_ASN1_OBJECT, i); | - | ||||||||||||||||||||||||
236 | return NULL; executed 609 times by 1 test: return ((void *)0) ; Executed by:
| 609 | ||||||||||||||||||||||||
237 | } | - | ||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||
239 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, | - | ||||||||||||||||||||||||
240 | long len) | - | ||||||||||||||||||||||||
241 | { | - | ||||||||||||||||||||||||
242 | ASN1_OBJECT *ret = NULL, tobj; | - | ||||||||||||||||||||||||
243 | const unsigned char *p; | - | ||||||||||||||||||||||||
244 | unsigned char *data; | - | ||||||||||||||||||||||||
245 | int i, length; | - | ||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | /* | - | ||||||||||||||||||||||||
248 | * Sanity check OID encoding. Need at least one content octet. MSB must | - | ||||||||||||||||||||||||
249 | * be clear in the last octet. can't have leading 0x80 in subidentifiers, | - | ||||||||||||||||||||||||
250 | * see: X.690 8.19.2 | - | ||||||||||||||||||||||||
251 | */ | - | ||||||||||||||||||||||||
252 | if (len <= 0 || len > INT_MAX || pp == NULL || (p = *pp) == NULL ||
| 0-896178 | ||||||||||||||||||||||||
253 | p[len - 1] & 0x80) {
| 8788-887390 | ||||||||||||||||||||||||
254 | ASN1err(ASN1_F_C2I_ASN1_OBJECT, ASN1_R_INVALID_OBJECT_ENCODING); | - | ||||||||||||||||||||||||
255 | return NULL; executed 10184 times by 1 test: return ((void *)0) ; Executed by:
| 10184 | ||||||||||||||||||||||||
256 | } | - | ||||||||||||||||||||||||
257 | /* Now 0 < len <= INT_MAX, so the cast is safe. */ | - | ||||||||||||||||||||||||
258 | length = (int)len; | - | ||||||||||||||||||||||||
259 | /* | - | ||||||||||||||||||||||||
260 | * Try to lookup OID in table: these are all valid encodings so if we get | - | ||||||||||||||||||||||||
261 | * a match we know the OID is valid. | - | ||||||||||||||||||||||||
262 | */ | - | ||||||||||||||||||||||||
263 | tobj.nid = NID_undef; | - | ||||||||||||||||||||||||
264 | tobj.data = p; | - | ||||||||||||||||||||||||
265 | tobj.length = length; | - | ||||||||||||||||||||||||
266 | tobj.flags = 0; | - | ||||||||||||||||||||||||
267 | i = OBJ_obj2nid(&tobj); | - | ||||||||||||||||||||||||
268 | if (i != NID_undef) {
| 310293-577097 | ||||||||||||||||||||||||
269 | /* | - | ||||||||||||||||||||||||
270 | * Return shared registered OID object: this improves efficiency | - | ||||||||||||||||||||||||
271 | * because we don't have to return a dynamically allocated OID | - | ||||||||||||||||||||||||
272 | * and NID lookups can use the cached value. | - | ||||||||||||||||||||||||
273 | */ | - | ||||||||||||||||||||||||
274 | ret = OBJ_nid2obj(i); | - | ||||||||||||||||||||||||
275 | if (a) {
| 0-577097 | ||||||||||||||||||||||||
276 | ASN1_OBJECT_free(*a); | - | ||||||||||||||||||||||||
277 | *a = ret; | - | ||||||||||||||||||||||||
278 | } executed 577097 times by 1 test: end of block Executed by:
| 577097 | ||||||||||||||||||||||||
279 | *pp += len; | - | ||||||||||||||||||||||||
280 | return ret; executed 577097 times by 1 test: return ret; Executed by:
| 577097 | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
282 | for (i = 0; i < length; i++, p++) {
| 307734-914259 | ||||||||||||||||||||||||
283 | if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
| 1005-859666 | ||||||||||||||||||||||||
284 | ASN1err(ASN1_F_C2I_ASN1_OBJECT, ASN1_R_INVALID_OBJECT_ENCODING); | - | ||||||||||||||||||||||||
285 | return NULL; executed 2559 times by 1 test: return ((void *)0) ; Executed by:
| 2559 | ||||||||||||||||||||||||
286 | } | - | ||||||||||||||||||||||||
287 | } executed 911700 times by 1 test: end of block Executed by:
| 911700 | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | /* | - | ||||||||||||||||||||||||
290 | * only the ASN1_OBJECTs from the 'table' will have values for ->sn or | - | ||||||||||||||||||||||||
291 | * ->ln | - | ||||||||||||||||||||||||
292 | */ | - | ||||||||||||||||||||||||
293 | if ((a == NULL) || ((*a) == NULL) ||
| 95-307639 | ||||||||||||||||||||||||
294 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
| 2864-211594 | ||||||||||||||||||||||||
295 | if ((ret = ASN1_OBJECT_new()) == NULL)
| 0-304870 | ||||||||||||||||||||||||
296 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
297 | } else executed 304870 times by 1 test: end of block Executed by:
| 304870 | ||||||||||||||||||||||||
298 | ret = (*a); executed 2864 times by 1 test: ret = (*a); Executed by:
| 2864 | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | p = *pp; | - | ||||||||||||||||||||||||
301 | /* detach data from object */ | - | ||||||||||||||||||||||||
302 | data = (unsigned char *)ret->data; | - | ||||||||||||||||||||||||
303 | ret->data = NULL; | - | ||||||||||||||||||||||||
304 | /* once detached we can change it */ | - | ||||||||||||||||||||||||
305 | if ((data == NULL) || (ret->length < length)) {
| 815-304870 | ||||||||||||||||||||||||
306 | ret->length = 0; | - | ||||||||||||||||||||||||
307 | OPENSSL_free(data); | - | ||||||||||||||||||||||||
308 | data = OPENSSL_malloc(length); | - | ||||||||||||||||||||||||
309 | if (data == NULL) {
| 0-305685 | ||||||||||||||||||||||||
310 | i = ERR_R_MALLOC_FAILURE; | - | ||||||||||||||||||||||||
311 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
312 | } | - | ||||||||||||||||||||||||
313 | ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; | - | ||||||||||||||||||||||||
314 | } executed 305685 times by 1 test: end of block Executed by:
| 305685 | ||||||||||||||||||||||||
315 | memcpy(data, p, length); | - | ||||||||||||||||||||||||
316 | /* reattach data to object, after which it remains const */ | - | ||||||||||||||||||||||||
317 | ret->data = data; | - | ||||||||||||||||||||||||
318 | ret->length = length; | - | ||||||||||||||||||||||||
319 | ret->sn = NULL; | - | ||||||||||||||||||||||||
320 | ret->ln = NULL; | - | ||||||||||||||||||||||||
321 | /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ | - | ||||||||||||||||||||||||
322 | p += length; | - | ||||||||||||||||||||||||
323 | - | |||||||||||||||||||||||||
324 | if (a != NULL)
| 95-307639 | ||||||||||||||||||||||||
325 | (*a) = ret; executed 307639 times by 1 test: (*a) = ret; Executed by:
| 307639 | ||||||||||||||||||||||||
326 | *pp = p; | - | ||||||||||||||||||||||||
327 | return ret; executed 307734 times by 1 test: return ret; Executed by:
| 307734 | ||||||||||||||||||||||||
328 | err: | - | ||||||||||||||||||||||||
329 | ASN1err(ASN1_F_C2I_ASN1_OBJECT, i); | - | ||||||||||||||||||||||||
330 | if ((a == NULL) || (*a != ret))
| 0 | ||||||||||||||||||||||||
331 | ASN1_OBJECT_free(ret); never executed: ASN1_OBJECT_free(ret); | 0 | ||||||||||||||||||||||||
332 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
333 | } | - | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | ASN1_OBJECT *ASN1_OBJECT_new(void) | - | ||||||||||||||||||||||||
336 | { | - | ||||||||||||||||||||||||
337 | ASN1_OBJECT *ret; | - | ||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||
339 | ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||||||||
340 | if (ret == NULL) {
| 0-357727 | ||||||||||||||||||||||||
341 | ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
342 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
343 | } | - | ||||||||||||||||||||||||
344 | ret->flags = ASN1_OBJECT_FLAG_DYNAMIC; | - | ||||||||||||||||||||||||
345 | return ret; executed 357727 times by 1 test: return ret; Executed by:
| 357727 | ||||||||||||||||||||||||
346 | } | - | ||||||||||||||||||||||||
347 | - | |||||||||||||||||||||||||
348 | void ASN1_OBJECT_free(ASN1_OBJECT *a) | - | ||||||||||||||||||||||||
349 | { | - | ||||||||||||||||||||||||
350 | if (a == NULL)
| 397533-1603245 | ||||||||||||||||||||||||
351 | return; executed 397533 times by 1 test: return; Executed by:
| 397533 | ||||||||||||||||||||||||
352 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
| 52857-1550388 | ||||||||||||||||||||||||
353 | #ifndef CONST_STRICT /* disable purely for compile-time strict | - | ||||||||||||||||||||||||
354 | * const checking. Doing this on a "real" | - | ||||||||||||||||||||||||
355 | * compile will cause memory leaks */ | - | ||||||||||||||||||||||||
356 | OPENSSL_free((void*)a->sn); | - | ||||||||||||||||||||||||
357 | OPENSSL_free((void*)a->ln); | - | ||||||||||||||||||||||||
358 | #endif | - | ||||||||||||||||||||||||
359 | a->sn = a->ln = NULL; | - | ||||||||||||||||||||||||
360 | } executed 52857 times by 1 test: end of block Executed by:
| 52857 | ||||||||||||||||||||||||
361 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
| 357727-1245518 | ||||||||||||||||||||||||
362 | OPENSSL_free((void*)a->data); | - | ||||||||||||||||||||||||
363 | a->data = NULL; | - | ||||||||||||||||||||||||
364 | a->length = 0; | - | ||||||||||||||||||||||||
365 | } executed 357727 times by 1 test: end of block Executed by:
| 357727 | ||||||||||||||||||||||||
366 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
| 357727-1245518 | ||||||||||||||||||||||||
367 | OPENSSL_free(a); executed 357727 times by 1 test: CRYPTO_free(a, __FILE__, 367); Executed by:
| 357727 | ||||||||||||||||||||||||
368 | } executed 1603245 times by 1 test: end of block Executed by:
| 1603245 | ||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||
370 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | - | ||||||||||||||||||||||||
371 | const char *sn, const char *ln) | - | ||||||||||||||||||||||||
372 | { | - | ||||||||||||||||||||||||
373 | ASN1_OBJECT o; | - | ||||||||||||||||||||||||
374 | - | |||||||||||||||||||||||||
375 | o.sn = sn; | - | ||||||||||||||||||||||||
376 | o.ln = ln; | - | ||||||||||||||||||||||||
377 | o.data = data; | - | ||||||||||||||||||||||||
378 | o.nid = nid; | - | ||||||||||||||||||||||||
379 | o.length = len; | - | ||||||||||||||||||||||||
380 | o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | | - | ||||||||||||||||||||||||
381 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | - | ||||||||||||||||||||||||
382 | return OBJ_dup(&o); never executed: return OBJ_dup(&o); | 0 | ||||||||||||||||||||||||
383 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |