OpenCoverage

asn1_lib.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/asn1_lib.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2016 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/cryptlib.h"-
13#include <openssl/asn1.h>-
14#include "asn1_locl.h"-
15-
16static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,-
17 long max);-
18static void asn1_put_length(unsigned char **pp, int length);-
19-
20static int _asn1_check_infinite_end(const unsigned char **p, long len)-
21{-
22 /*-
23 * If there is 0 or 1 byte left, the length check should pick things up-
24 */-
25 if (len <= 0)
len <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
26 return 1;
never executed: return 1;
0
27 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) {
(len >= 2)Description
TRUEnever evaluated
FALSEnever evaluated
((*p)[0] == 0)Description
TRUEnever evaluated
FALSEnever evaluated
((*p)[1] == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
28 (*p) += 2;-
29 return 1;
never executed: return 1;
0
30 }-
31 return 0;
never executed: return 0;
0
32}-
33-
34int ASN1_check_infinite_end(unsigned char **p, long len)-
35{-
36 return _asn1_check_infinite_end((const unsigned char **)p, len);
never executed: return _asn1_check_infinite_end((const unsigned char **)p, len);
0
37}-
38-
39int ASN1_const_check_infinite_end(const unsigned char **p, long len)-
40{-
41 return _asn1_check_infinite_end(p, len);
never executed: return _asn1_check_infinite_end(p, len);
0
42}-
43-
44int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,-
45 int *pclass, long omax)-
46{-
47 int i, ret;-
48 long l;-
49 const unsigned char *p = *pp;-
50 int tag, xclass, inf;-
51 long max = omax;-
52-
53 if (!max)
!maxDescription
TRUEevaluated 2805 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12288196 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
2805-12288196
54 goto err;
executed 2805 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
2805
55 ret = (*p & V_ASN1_CONSTRUCTED);-
56 xclass = (*p & V_ASN1_PRIVATE);-
57 i = *p & V_ASN1_PRIMITIVE_TAG;-
58 if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */
i == 0x1fDescription
TRUEevaluated 42636 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12245560 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
42636-12245560
59 p++;-
60 if (--max == 0)
--max == 0Description
TRUEevaluated 1080 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 41556 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1080-41556
61 goto err;
executed 1080 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
1080
62 l = 0;-
63 while (*p & 0x80) {
*p & 0x80Description
TRUEevaluated 19850 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 39885 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
19850-39885
64 l <<= 7L;-
65 l |= *(p++) & 0x7f;-
66 if (--max == 0)
--max == 0Description
TRUEevaluated 819 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19031 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
819-19031
67 goto err;
executed 819 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
819
68 if (l > (INT_MAX >> 7L))
l > (0x7fffffff >> 7L)Description
TRUEevaluated 852 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 18179 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
852-18179
69 goto err;
executed 852 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
852
70 }
executed 18179 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
18179
71 l <<= 7L;-
72 l |= *(p++) & 0x7f;-
73 tag = (int)l;-
74 if (--max == 0)
--max == 0Description
TRUEevaluated 1219 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 38666 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1219-38666
75 goto err;
executed 1219 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
1219
76 } else {
executed 38666 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
38666
77 tag = i;-
78 p++;-
79 if (--max == 0)
--max == 0Description
TRUEevaluated 8459 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12237101 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
8459-12237101
80 goto err;
executed 8459 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
8459
81 }
executed 12237101 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
12237101
82 *ptag = tag;-
83 *pclass = xclass;-
84 if (!asn1_get_length(&p, &inf, plength, max))
!asn1_get_leng... plength, max)Description
TRUEevaluated 9320 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12266447 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
9320-12266447
85 goto err;
executed 9320 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
9320
86-
87 if (inf && !(ret & V_ASN1_CONSTRUCTED))
infDescription
TRUEevaluated 3662987 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8603460 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
!(ret & 0x20)Description
TRUEevaluated 2136 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3660851 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2136-8603460
88 goto err;
executed 2136 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
2136
89-
90 if (*plength > (omax - (p - *pp))) {
*plength > (omax - (p - *pp))Description
TRUEevaluated 46553 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12217758 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
46553-12217758
91 ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG);-
92 /*-
93 * Set this so that even if things are not long enough the values are-
94 * set correctly-
95 */-
96 ret |= 0x80;-
97 }
executed 46553 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
46553
98 *pp = p;-
99 return ret | inf;
executed 12264311 times by 2 tests: return ret | inf;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
12264311
100 err:-
101 ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_HEADER_TOO_LONG);-
102 return 0x80;
executed 26690 times by 1 test: return 0x80;
Executed by:
  • libcrypto.so.1.1
26690
103}-
104-
105/*-
106 * Decode a length field.-
107 * The short form is a single byte defining a length 0 - 127.-
108 * The long form is a byte 0 - 127 with the top bit set and this indicates-
109 * the number of following octets that contain the length. These octets-
110 * are stored most significant digit first.-
111 */-
112static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,-
113 long max)-
114{-
115 const unsigned char *p = *pp;-
116 unsigned long ret = 0;-
117 int i;-
118-
119 if (max-- < 1)
max-- < 1Description
TRUEnever evaluated
FALSEevaluated 12275767 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-12275767
120 return 0;
never executed: return 0;
0
121 if (*p == 0x80) {
*p == 0x80Description
TRUEevaluated 3662987 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8612780 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
3662987-8612780
122 *inf = 1;-
123 p++;-
124 } else {
executed 3662987 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3662987
125 *inf = 0;-
126 i = *p & 0x7f;-
127 if (*p++ & 0x80) {
*p++ & 0x80Description
TRUEevaluated 376881 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8235899 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
376881-8235899
128 if (max < i + 1)
max < i + 1Description
TRUEevaluated 7311 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 369570 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7311-369570
129 return 0;
executed 7311 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
7311
130 /* Skip leading zeroes */-
131 while (i > 0 && *p == 0) {
i > 0Description
TRUEevaluated 375212 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 66369 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
*p == 0Description
TRUEevaluated 72011 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 303201 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
66369-375212
132 p++;-
133 i--;-
134 }
executed 72011 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
72011
135 if (i > (int)sizeof(long))
i > (int)sizeof(long)Description
TRUEevaluated 1099 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 368471 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1099-368471
136 return 0;
executed 1099 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1099
137 while (i > 0) {
i > 0Description
TRUEevaluated 441726 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 368471 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
368471-441726
138 ret <<= 8;-
139 ret |= *p++;-
140 i--;-
141 }
executed 441726 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
441726
142 if (ret > LONG_MAX)
ret > 0x7fffffffffffffffLDescription
TRUEevaluated 910 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 367561 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
910-367561
143 return 0;
executed 910 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
910
144 } else
executed 367561 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
367561
145 ret = i;
executed 8235899 times by 2 tests: ret = i;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
8235899
146 }-
147 *pp = p;-
148 *rl = (long)ret;-
149 return 1;
executed 12266447 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
12266447
150}-
151-
152/*-
153 * class 0 is constructed constructed == 2 for indefinite length constructed-
154 */-
155void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,-
156 int xclass)-
157{-
158 unsigned char *p = *pp;-
159 int i, ttag;-
160-
161 i = (constructed) ? V_ASN1_CONSTRUCTED : 0;
(constructed)Description
TRUEevaluated 477168 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 661176 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
477168-661176
162 i |= (xclass & V_ASN1_PRIVATE);-
163 if (tag < 31)
tag < 31Description
TRUEevaluated 1130656 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 7688 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7688-1130656
164 *(p++) = i | (tag & V_ASN1_PRIMITIVE_TAG);
executed 1130656 times by 2 tests: *(p++) = i | (tag & 0x1f);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1130656
165 else {-
166 *(p++) = i | V_ASN1_PRIMITIVE_TAG;-
167 for (i = 0, ttag = tag; ttag > 0; i++)
ttag > 0Description
TRUEevaluated 15736 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7688 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7688-15736
168 ttag >>= 7;
executed 15736 times by 1 test: ttag >>= 7;
Executed by:
  • libcrypto.so.1.1
15736
169 ttag = i;-
170 while (i-- > 0) {
i-- > 0Description
TRUEevaluated 15736 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7688 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7688-15736
171 p[i] = tag & 0x7f;-
172 if (i != (ttag - 1))
i != (ttag - 1)Description
TRUEevaluated 8048 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7688 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7688-8048
173 p[i] |= 0x80;
executed 8048 times by 1 test: p[i] |= 0x80;
Executed by:
  • libcrypto.so.1.1
8048
174 tag >>= 7;-
175 }
executed 15736 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
15736
176 p += ttag;-
177 }
executed 7688 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
7688
178 if (constructed == 2)
constructed == 2Description
TRUEevaluated 480 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1137864 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
480-1137864
179 *(p++) = 0x80;
executed 480 times by 1 test: *(p++) = 0x80;
Executed by:
  • libcrypto.so.1.1
480
180 else-
181 asn1_put_length(&p, length);
executed 1137864 times by 2 tests: asn1_put_length(&p, length);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1137864
182 *pp = p;-
183}
executed 1138344 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1138344
184-
185int ASN1_put_eoc(unsigned char **pp)-
186{-
187 unsigned char *p = *pp;-
188 *p++ = 0;-
189 *p++ = 0;-
190 *pp = p;-
191 return 2;
executed 480 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
480
192}-
193-
194static void asn1_put_length(unsigned char **pp, int length)-
195{-
196 unsigned char *p = *pp;-
197 int i, l;-
198 if (length <= 127)
length <= 127Description
TRUEevaluated 1084378 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 53486 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
53486-1084378
199 *(p++) = (unsigned char)length;
executed 1084378 times by 2 tests: *(p++) = (unsigned char)length;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1084378
200 else {-
201 l = length;-
202 for (i = 0; l > 0; i++)
l > 0Description
TRUEevaluated 96912 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53486 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
53486-96912
203 l >>= 8;
executed 96912 times by 1 test: l >>= 8;
Executed by:
  • libcrypto.so.1.1
96912
204 *(p++) = i | 0x80;-
205 l = i;-
206 while (i-- > 0) {
i-- > 0Description
TRUEevaluated 96912 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53486 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
53486-96912
207 p[i] = length & 0xff;-
208 length >>= 8;-
209 }
executed 96912 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
96912
210 p += l;-
211 }
executed 53486 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
53486
212 *pp = p;-
213}
executed 1137864 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1137864
214-
215int ASN1_object_size(int constructed, int length, int tag)-
216{-
217 int ret = 1;-
218 if (length < 0)
length < 0Description
TRUEnever evaluated
FALSEevaluated 4202881 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-4202881
219 return -1;
never executed: return -1;
0
220 if (tag >= 31) {
tag >= 31Description
TRUEevaluated 32684 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4170197 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
32684-4170197
221 while (tag > 0) {
tag > 0Description
TRUEevaluated 68037 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 32684 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
32684-68037
222 tag >>= 7;-
223 ret++;-
224 }
executed 68037 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
68037
225 }
executed 32684 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
32684
226 if (constructed == 2) {
constructed == 2Description
TRUEevaluated 2016 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4200865 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
2016-4200865
227 ret += 3;-
228 } else {
executed 2016 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2016
229 ret++;-
230 if (length > 127) {
length > 127Description
TRUEevaluated 139698 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4061167 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
139698-4061167
231 int tmplen = length;-
232 while (tmplen > 0) {
tmplen > 0Description
TRUEevaluated 252444 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 139698 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
139698-252444
233 tmplen >>= 8;-
234 ret++;-
235 }
executed 252444 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
252444
236 }
executed 139698 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
139698
237 }
executed 4200865 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4200865
238 if (ret >= INT_MAX - length)
ret >= 0x7fffffff - lengthDescription
TRUEnever evaluated
FALSEevaluated 4202881 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-4202881
239 return -1;
never executed: return -1;
0
240 return ret + length;
executed 4202881 times by 2 tests: return ret + length;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
4202881
241}-
242-
243int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)-
244{-
245 if (str == NULL)
str == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 25360 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-25360
246 return 0;
never executed: return 0;
0
247 dst->type = str->type;-
248 if (!ASN1_STRING_set(dst, str->data, str->length))
!ASN1_STRING_s..., str->length)Description
TRUEnever evaluated
FALSEevaluated 25360 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-25360
249 return 0;
never executed: return 0;
0
250 /* Copy flags but preserve embed value */-
251 dst->flags &= ASN1_STRING_FLAG_EMBED;-
252 dst->flags |= str->flags & ~ASN1_STRING_FLAG_EMBED;-
253 return 1;
executed 25360 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
25360
254}-
255-
256ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str)-
257{-
258 ASN1_STRING *ret;-
259 if (!str)
!strDescription
TRUEnever evaluated
FALSEevaluated 2849 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2849
260 return NULL;
never executed: return ((void *)0) ;
0
261 ret = ASN1_STRING_new();-
262 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2849 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2849
263 return NULL;
never executed: return ((void *)0) ;
0
264 if (!ASN1_STRING_copy(ret, str)) {
!ASN1_STRING_copy(ret, str)Description
TRUEnever evaluated
FALSEevaluated 2849 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2849
265 ASN1_STRING_free(ret);-
266 return NULL;
never executed: return ((void *)0) ;
0
267 }-
268 return ret;
executed 2849 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
2849
269}-
270-
271int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)-
272{-
273 unsigned char *c;-
274 const char *data = _data;-
275-
276 if (len < 0) {
len < 0Description
TRUEevaluated 102 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1135926 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
102-1135926
277 if (data == NULL)
data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 102 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-102
278 return 0;
never executed: return 0;
0
279 else-
280 len = strlen(data);
executed 102 times by 1 test: len = strlen(data);
Executed by:
  • libcrypto.so.1.1
102
281 }-
282 if ((str->length <= len) || (str->data == NULL)) {
(str->length <= len)Description
TRUEevaluated 1136028 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEnever evaluated
(str->data == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0-1136028
283 c = str->data;-
284 str->data = OPENSSL_realloc(c, len + 1);-
285 if (str->data == NULL) {
str->data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1136028 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-1136028
286 ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);-
287 str->data = c;-
288 return 0;
never executed: return 0;
0
289 }-
290 }
executed 1136028 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1136028
291 str->length = len;-
292 if (data != NULL) {
data != ((void *)0)Description
TRUEevaluated 858141 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 277887 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
277887-858141
293 memcpy(str->data, data, len);-
294 /* an allowance for strings :-) */-
295 str->data[len] = '\0';-
296 }
executed 858141 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
858141
297 return 1;
executed 1136028 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1136028
298}-
299-
300void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)-
301{-
302 OPENSSL_free(str->data);-
303 str->data = data;-
304 str->length = len;-
305}
executed 483 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
483
306-
307ASN1_STRING *ASN1_STRING_new(void)-
308{-
309 return ASN1_STRING_type_new(V_ASN1_OCTET_STRING);
executed 11214 times by 1 test: return ASN1_STRING_type_new(4);
Executed by:
  • libcrypto.so.1.1
11214
310}-
311-
312ASN1_STRING *ASN1_STRING_type_new(int type)-
313{-
314 ASN1_STRING *ret;-
315-
316 ret = OPENSSL_zalloc(sizeof(*ret));-
317 if (ret == NULL) {
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1331089 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-1331089
318 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);-
319 return NULL;
never executed: return ((void *)0) ;
0
320 }-
321 ret->type = type;-
322 return ret;
executed 1331089 times by 2 tests: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1331089
323}-
324-
325void asn1_string_embed_free(ASN1_STRING *a, int embed)-
326{-
327 if (a == NULL)
a == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1704197 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-1704197
328 return;
never executed: return;
0
329 if (!(a->flags & ASN1_STRING_FLAG_NDEF))
!(a->flags & 0x010)Description
TRUEevaluated 1704152 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
45-1704152
330 OPENSSL_free(a->data);
executed 1704152 times by 2 tests: CRYPTO_free(a->data, __FILE__, 330);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1704152
331 if (embed == 0)
embed == 0Description
TRUEevaluated 1331089 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 373108 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
373108-1331089
332 OPENSSL_free(a);
executed 1331089 times by 2 tests: CRYPTO_free(a, __FILE__, 332);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1331089
333}
executed 1704197 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1704197
334-
335void ASN1_STRING_free(ASN1_STRING *a)-
336{-
337 if (a == NULL)
a == ((void *)0)Description
TRUEevaluated 541406 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 258109 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
258109-541406
338 return;
executed 541406 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
541406
339 asn1_string_embed_free(a, a->flags & ASN1_STRING_FLAG_EMBED);-
340}
executed 258109 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
258109
341-
342void ASN1_STRING_clear_free(ASN1_STRING *a)-
343{-
344 if (a == NULL)
a == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 65 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3-65
345 return;
executed 3 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
3
346 if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF))
a->dataDescription
TRUEevaluated 65 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!(a->flags & 0x010)Description
TRUEevaluated 65 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-65
347 OPENSSL_cleanse(a->data, a->length);
executed 65 times by 1 test: OPENSSL_cleanse(a->data, a->length);
Executed by:
  • libcrypto.so.1.1
65
348 ASN1_STRING_free(a);-
349}
executed 65 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
65
350-
351int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)-
352{-
353 int i;-
354-
355 i = (a->length - b->length);-
356 if (i == 0) {
i == 0Description
TRUEevaluated 2878 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-2878
357 i = memcmp(a->data, b->data, a->length);-
358 if (i == 0)
i == 0Description
TRUEevaluated 2736 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
142-2736
359 return a->type - b->type;
executed 2736 times by 1 test: return a->type - b->type;
Executed by:
  • libcrypto.so.1.1
2736
360 else-
361 return i;
executed 142 times by 1 test: return i;
Executed by:
  • libcrypto.so.1.1
142
362 } else-
363 return i;
executed 9 times by 1 test: return i;
Executed by:
  • libcrypto.so.1.1
9
364}-
365-
366int ASN1_STRING_length(const ASN1_STRING *x)-
367{-
368 return x->length;
executed 208482 times by 1 test: return x->length;
Executed by:
  • libcrypto.so.1.1
208482
369}-
370-
371void ASN1_STRING_length_set(ASN1_STRING *x, int len)-
372{-
373 x->length = len;-
374}
never executed: end of block
0
375-
376int ASN1_STRING_type(const ASN1_STRING *x)-
377{-
378 return x->type;
never executed: return x->type;
0
379}-
380-
381const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)-
382{-
383 return x->data;
executed 210900 times by 1 test: return x->data;
Executed by:
  • libcrypto.so.1.1
210900
384}-
385-
386# if OPENSSL_API_COMPAT < 0x10100000L-
387unsigned char *ASN1_STRING_data(ASN1_STRING *x)-
388{-
389 return x->data;
never executed: return x->data;
0
390}-
391#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2