OpenCoverage

a_utf8.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_utf8.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 "internal/cryptlib.h"-
12#include <openssl/asn1.h>-
13-
14/* UTF8 utilities */-
15-
16/*--
17 * This parses a UTF8 string one character at a time. It is passed a pointer-
18 * to the string and the length of the string. It sets 'value' to the value of-
19 * the current character. It returns the number of characters read or a-
20 * negative error code:-
21 * -1 = string too short-
22 * -2 = illegal character-
23 * -3 = subsequent characters not of the form 10xxxxxx-
24 * -4 = character encoded incorrectly (not minimal length).-
25 */-
26-
27int UTF8_getc(const unsigned char *str, int len, unsigned long *val)-
28{-
29 const unsigned char *p;-
30 unsigned long value;-
31 int ret;-
32 if (len <= 0)
len <= 0Description
TRUEnever evaluated
FALSEevaluated 1666089 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1666089
33 return 0;
never executed: return 0;
0
34 p = str;-
35-
36 /* Check syntax and work out the encoded value (if correct) */-
37 if ((*p & 0x80) == 0) {
(*p & 0x80) == 0Description
TRUEevaluated 1643425 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 22664 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
22664-1643425
38 value = *p++ & 0x7f;-
39 ret = 1;-
40 } else if ((*p & 0xe0) == 0xc0) {
executed 1643425 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
(*p & 0xe0) == 0xc0Description
TRUEevaluated 4782 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 17882 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4782-1643425
41 if (len < 2)
len < 2Description
TRUEevaluated 471 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4311 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
471-4311
42 return -1;
executed 471 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
471
43 if ((p[1] & 0xc0) != 0x80)
(p[1] & 0xc0) != 0x80Description
TRUEevaluated 522 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3789 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
522-3789
44 return -3;
executed 522 times by 1 test: return -3;
Executed by:
  • libcrypto.so.1.1
522
45 value = (*p++ & 0x1f) << 6;-
46 value |= *p++ & 0x3f;-
47 if (value < 0x80)
value < 0x80Description
TRUEevaluated 272 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3517 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
272-3517
48 return -4;
executed 272 times by 1 test: return -4;
Executed by:
  • libcrypto.so.1.1
272
49 ret = 2;-
50 } else if ((*p & 0xf0) == 0xe0) {
executed 3517 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
(*p & 0xf0) == 0xe0Description
TRUEevaluated 2695 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 15187 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2695-15187
51 if (len < 3)
len < 3Description
TRUEevaluated 409 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2286 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
409-2286
52 return -1;
executed 409 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
409
53 if (((p[1] & 0xc0) != 0x80)
((p[1] & 0xc0) != 0x80)Description
TRUEevaluated 414 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1872 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
414-1872
54 || ((p[2] & 0xc0) != 0x80))
((p[2] & 0xc0) != 0x80)Description
TRUEevaluated 423 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1449 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
423-1449
55 return -3;
executed 837 times by 1 test: return -3;
Executed by:
  • libcrypto.so.1.1
837
56 value = (*p++ & 0xf) << 12;-
57 value |= (*p++ & 0x3f) << 6;-
58 value |= *p++ & 0x3f;-
59 if (value < 0x800)
value < 0x800Description
TRUEevaluated 274 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1175 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
274-1175
60 return -4;
executed 274 times by 1 test: return -4;
Executed by:
  • libcrypto.so.1.1
274
61 ret = 3;-
62 } else if ((*p & 0xf8) == 0xf0) {
executed 1175 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
(*p & 0xf8) == 0xf0Description
TRUEevaluated 2973 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12214 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1175-12214
63 if (len < 4)
len < 4Description
TRUEevaluated 401 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2572 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
401-2572
64 return -1;
executed 401 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
401
65 if (((p[1] & 0xc0) != 0x80)
((p[1] & 0xc0) != 0x80)Description
TRUEevaluated 410 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2162 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
410-2162
66 || ((p[2] & 0xc0) != 0x80)
((p[2] & 0xc0) != 0x80)Description
TRUEevaluated 429 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1733 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
429-1733
67 || ((p[3] & 0xc0) != 0x80))
((p[3] & 0xc0) != 0x80)Description
TRUEevaluated 400 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1333 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
400-1333
68 return -3;
executed 1239 times by 1 test: return -3;
Executed by:
  • libcrypto.so.1.1
1239
69 value = ((unsigned long)(*p++ & 0x7)) << 18;-
70 value |= (*p++ & 0x3f) << 12;-
71 value |= (*p++ & 0x3f) << 6;-
72 value |= *p++ & 0x3f;-
73 if (value < 0x10000)
value < 0x10000Description
TRUEevaluated 272 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1061 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
272-1061
74 return -4;
executed 272 times by 1 test: return -4;
Executed by:
  • libcrypto.so.1.1
272
75 ret = 4;-
76 } else if ((*p & 0xfc) == 0xf8) {
executed 1061 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
(*p & 0xfc) == 0xf8Description
TRUEevaluated 4625 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7589 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1061-7589
77 if (len < 5)
len < 5Description
TRUEevaluated 591 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4034 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
591-4034
78 return -1;
executed 591 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
591
79 if (((p[1] & 0xc0) != 0x80)
((p[1] & 0xc0) != 0x80)Description
TRUEevaluated 345 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3689 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
345-3689
80 || ((p[2] & 0xc0) != 0x80)
((p[2] & 0xc0) != 0x80)Description
TRUEevaluated 283 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3406 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
283-3406
81 || ((p[3] & 0xc0) != 0x80)
((p[3] & 0xc0) != 0x80)Description
TRUEevaluated 315 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3091 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
315-3091
82 || ((p[4] & 0xc0) != 0x80))
((p[4] & 0xc0) != 0x80)Description
TRUEevaluated 477 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2614 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
477-2614
83 return -3;
executed 1420 times by 1 test: return -3;
Executed by:
  • libcrypto.so.1.1
1420
84 value = ((unsigned long)(*p++ & 0x3)) << 24;-
85 value |= ((unsigned long)(*p++ & 0x3f)) << 18;-
86 value |= ((unsigned long)(*p++ & 0x3f)) << 12;-
87 value |= (*p++ & 0x3f) << 6;-
88 value |= *p++ & 0x3f;-
89 if (value < 0x200000)
value < 0x200000Description
TRUEevaluated 272 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2342 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
272-2342
90 return -4;
executed 272 times by 1 test: return -4;
Executed by:
  • libcrypto.so.1.1
272
91 ret = 5;-
92 } else if ((*p & 0xfe) == 0xfc) {
executed 2342 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
(*p & 0xfe) == 0xfcDescription
TRUEevaluated 6886 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 703 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
703-6886
93 if (len < 6)
len < 6Description
TRUEevaluated 283 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6603 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
283-6603
94 return -1;
executed 283 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
283
95 if (((p[1] & 0xc0) != 0x80)
((p[1] & 0xc0) != 0x80)Description
TRUEevaluated 638 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5965 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
638-5965
96 || ((p[2] & 0xc0) != 0x80)
((p[2] & 0xc0) != 0x80)Description
TRUEevaluated 287 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5678 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
287-5678
97 || ((p[3] & 0xc0) != 0x80)
((p[3] & 0xc0) != 0x80)Description
TRUEevaluated 274 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5404 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
274-5404
98 || ((p[4] & 0xc0) != 0x80)
((p[4] & 0xc0) != 0x80)Description
TRUEevaluated 272 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5132 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
272-5132
99 || ((p[5] & 0xc0) != 0x80))
((p[5] & 0xc0) != 0x80)Description
TRUEevaluated 283 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4849 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
283-4849
100 return -3;
executed 1754 times by 1 test: return -3;
Executed by:
  • libcrypto.so.1.1
1754
101 value = ((unsigned long)(*p++ & 0x1)) << 30;-
102 value |= ((unsigned long)(*p++ & 0x3f)) << 24;-
103 value |= ((unsigned long)(*p++ & 0x3f)) << 18;-
104 value |= ((unsigned long)(*p++ & 0x3f)) << 12;-
105 value |= (*p++ & 0x3f) << 6;-
106 value |= *p++ & 0x3f;-
107 if (value < 0x4000000)
value < 0x4000000Description
TRUEevaluated 273 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4576 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
273-4576
108 return -4;
executed 273 times by 1 test: return -4;
Executed by:
  • libcrypto.so.1.1
273
109 ret = 6;-
110 } else
executed 4576 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4576
111 return -2;
executed 703 times by 1 test: return -2;
Executed by:
  • libcrypto.so.1.1
703
112 *val = value;-
113 return ret;
executed 1656096 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1656096
114}-
115-
116/*-
117 * This takes a character 'value' and writes the UTF8 encoded value in 'str'-
118 * where 'str' is a buffer containing 'len' characters. Returns the number of-
119 * characters written or -1 if 'len' is too small. 'str' can be set to NULL-
120 * in which case it just returns the number of characters. It will need at-
121 * most 6 characters.-
122 */-
123-
124int UTF8_putc(unsigned char *str, int len, unsigned long value)-
125{-
126 if (!str)
!strDescription
TRUEevaluated 570249 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 650339 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
570249-650339
127 len = 6; /* Maximum we will need */
executed 570249 times by 1 test: len = 6;
Executed by:
  • libcrypto.so.1.1
570249
128 else if (len <= 0)
len <= 0Description
TRUEnever evaluated
FALSEevaluated 650339 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-650339
129 return -1;
never executed: return -1;
0
130 if (value < 0x80) {
value < 0x80Description
TRUEevaluated 1014640 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 205948 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
205948-1014640
131 if (str)
strDescription
TRUEevaluated 527177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 487463 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
487463-527177
132 *str = (unsigned char)value;
executed 527177 times by 1 test: *str = (unsigned char)value;
Executed by:
  • libcrypto.so.1.1
527177
133 return 1;
executed 1014640 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1014640
134 }-
135 if (value < 0x800) {
value < 0x800Description
TRUEevaluated 127444 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 78504 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
78504-127444
136 if (len < 2)
len < 2Description
TRUEnever evaluated
FALSEevaluated 127444 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-127444
137 return -1;
never executed: return -1;
0
138 if (str) {
strDescription
TRUEevaluated 64891 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 62553 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
62553-64891
139 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);-
140 *str = (unsigned char)((value & 0x3f) | 0x80);-
141 }
executed 64891 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
64891
142 return 2;
executed 127444 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
127444
143 }-
144 if (value < 0x10000) {
value < 0x10000Description
TRUEevaluated 64050 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14454 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
14454-64050
145 if (len < 3)
len < 3Description
TRUEnever evaluated
FALSEevaluated 64050 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-64050
146 return -1;
never executed: return -1;
0
147 if (str) {
strDescription
TRUEevaluated 50550 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 13500 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
13500-50550
148 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);-
149 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);-
150 *str = (unsigned char)((value & 0x3f) | 0x80);-
151 }
executed 50550 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
50550
152 return 3;
executed 64050 times by 1 test: return 3;
Executed by:
  • libcrypto.so.1.1
64050
153 }-
154 if (value < 0x200000) {
value < 0x200000Description
TRUEevaluated 2142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12312 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2142-12312
155 if (len < 4)
len < 4Description
TRUEnever evaluated
FALSEevaluated 2142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2142
156 return -1;
never executed: return -1;
0
157 if (str) {
strDescription
TRUEevaluated 1088 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1054 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1054-1088
158 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);-
159 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);-
160 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);-
161 *str = (unsigned char)((value & 0x3f) | 0x80);-
162 }
executed 1088 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1088
163 return 4;
executed 2142 times by 1 test: return 4;
Executed by:
  • libcrypto.so.1.1
2142
164 }-
165 if (value < 0x4000000) {
value < 0x4000000Description
TRUEevaluated 2684 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9628 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2684-9628
166 if (len < 5)
len < 5Description
TRUEnever evaluated
FALSEevaluated 2684 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2684
167 return -1;
never executed: return -1;
0
168 if (str) {
strDescription
TRUEevaluated 1453 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1231 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1231-1453
169 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);-
170 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);-
171 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);-
172 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);-
173 *str = (unsigned char)((value & 0x3f) | 0x80);-
174 }
executed 1453 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1453
175 return 5;
executed 2684 times by 1 test: return 5;
Executed by:
  • libcrypto.so.1.1
2684
176 }-
177 if (len < 6)
len < 6Description
TRUEnever evaluated
FALSEevaluated 9628 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9628
178 return -1;
never executed: return -1;
0
179 if (str) {
strDescription
TRUEevaluated 5180 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4448 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4448-5180
180 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);-
181 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);-
182 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);-
183 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);-
184 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);-
185 *str = (unsigned char)((value & 0x3f) | 0x80);-
186 }
executed 5180 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
5180
187 return 6;
executed 9628 times by 1 test: return 6;
Executed by:
  • libcrypto.so.1.1
9628
188}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2