OpenCoverage

a_strnid.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_strnid.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1999-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 "internal/cryptlib.h"-
12#include <openssl/asn1.h>-
13#include <openssl/objects.h>-
14-
15static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;-
16static void st_free(ASN1_STRING_TABLE *tbl);-
17static int sk_table_cmp(const ASN1_STRING_TABLE *const *a,-
18 const ASN1_STRING_TABLE *const *b);-
19-
20/*-
21 * This is the global mask for the mbstring functions: this is use to mask-
22 * out certain types (such as BMPString and UTF8String) because certain-
23 * software (e.g. Netscape) has problems with them.-
24 */-
25-
26static unsigned long global_mask = B_ASN1_UTF8STRING;-
27-
28void ASN1_STRING_set_default_mask(unsigned long mask)-
29{-
30 global_mask = mask;-
31}
executed 16 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
16
32-
33unsigned long ASN1_STRING_get_default_mask(void)-
34{-
35 return global_mask;
never executed: return global_mask;
0
36}-
37-
38/*--
39 * This function sets the default to various "flavours" of configuration.-
40 * based on an ASCII string. Currently this is:-
41 * MASK:XXXX : a numerical mask value.-
42 * nobmp : Don't use BMPStrings (just Printable, T61).-
43 * pkix : PKIX recommendation in RFC2459.-
44 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).-
45 * default: the default value, Printable, T61, BMP.-
46 */-
47-
48int ASN1_STRING_set_default_mask_asc(const char *p)-
49{-
50 unsigned long mask;-
51 char *end;-
52-
53 if (strncmp(p, "MASK:", 5) == 0) {
never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "MASK:" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(__extension__..." , 5 ))) == 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
__builtin_constant_p ( 5 )Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
__builtin_constant_p ( p )Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
strlen ( p ) <...size_t) ( 5 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons..._p ( "MASK:" )Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
strlen ( "MASK...size_t) ( 5 ))Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-16
54 if (!p[5])
!p[5]Description
TRUEnever evaluated
FALSEnever evaluated
0
55 return 0;
never executed: return 0;
0
56 mask = strtoul(p + 5, &end, 0);-
57 if (*end)
*endDescription
TRUEnever evaluated
FALSEnever evaluated
0
58 return 0;
never executed: return 0;
0
59 } else if (strcmp(p, "nombstr") == 0)
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "nombstr" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-16
60 mask = ~((unsigned long)(B_ASN1_BMPSTRING | B_ASN1_UTF8STRING));
never executed: mask = ~((unsigned long)(0x0800 | 0x2000));
0
61 else if (strcmp(p, "pkix") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "pkix" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-16
62 mask = ~((unsigned long)B_ASN1_T61STRING);
never executed: mask = ~((unsigned long)0x0004);
0
63 else if (strcmp(p, "utf8only") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "utf8only" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-16
64 mask = B_ASN1_UTF8STRING;
executed 16 times by 1 test: mask = 0x2000;
Executed by:
  • libcrypto.so.1.1
16
65 else if (strcmp(p, "default") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "default" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
66 mask = 0xFFFFFFFFL;
never executed: mask = 0xFFFFFFFFL;
0
67 else-
68 return 0;
never executed: return 0;
0
69 ASN1_STRING_set_default_mask(mask);-
70 return 1;
executed 16 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
16
71}-
72-
73/*-
74 * The following function generates an ASN1_STRING based on limits in a-
75 * table. Frequently the types and length of an ASN1_STRING are restricted by-
76 * a corresponding OID. For example certificates and certificate requests.-
77 */-
78-
79ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,-
80 const unsigned char *in, int inlen,-
81 int inform, int nid)-
82{-
83 ASN1_STRING_TABLE *tbl;-
84 ASN1_STRING *str = NULL;-
85 unsigned long mask;-
86 int ret;-
87-
88 if (out == NULL)
out == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 765 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-765
89 out = &str;
never executed: out = &str;
0
90 tbl = ASN1_STRING_TABLE_get(nid);-
91 if (tbl != NULL) {
tbl != ((void *)0)Description
TRUEevaluated 765 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-765
92 mask = tbl->mask;-
93 if (!(tbl->flags & STABLE_NO_MASK))
!(tbl->flags & 0x02)Description
TRUEevaluated 395 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
370-395
94 mask &= global_mask;
executed 395 times by 1 test: mask &= global_mask;
Executed by:
  • libcrypto.so.1.1
395
95 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,-
96 tbl->minsize, tbl->maxsize);-
97 } else {
executed 765 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
765
98 ret = ASN1_mbstring_copy(out, in, inlen, inform,-
99 DIRSTRING_TYPE & global_mask);-
100 }
never executed: end of block
0
101 if (ret <= 0)
ret <= 0Description
TRUEnever evaluated
FALSEevaluated 765 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-765
102 return NULL;
never executed: return ((void *)0) ;
0
103 return *out;
executed 765 times by 1 test: return *out;
Executed by:
  • libcrypto.so.1.1
765
104}-
105-
106/*-
107 * Now the tables and helper functions for the string table:-
108 */-
109-
110#include "tbl_standard.h"-
111-
112static int sk_table_cmp(const ASN1_STRING_TABLE *const *a,-
113 const ASN1_STRING_TABLE *const *b)-
114{-
115 return (*a)->nid - (*b)->nid;
executed 6 times by 1 test: return (*a)->nid - (*b)->nid;
Executed by:
  • libcrypto.so.1.1
6
116}-
117-
118DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);-
119-
120static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b)-
121{-
122 return a->nid - b->nid;
executed 2753 times by 1 test: return a->nid - b->nid;
Executed by:
  • libcrypto.so.1.1
2753
123}-
124-
125IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);
executed 2753 times by 1 test: return table_cmp(a,b);
Executed by:
  • libcrypto.so.1.1
executed 770 times by 1 test: return (ASN1_STRING_TABLE *)OBJ_bsearch_(key, base, num, sizeof(ASN1_STRING_TABLE), table_cmp_BSEARCH_CMP_FN);
Executed by:
  • libcrypto.so.1.1
770-2753
126-
127ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)-
128{-
129 int idx;-
130 ASN1_STRING_TABLE fnd;-
131-
132 fnd.nid = nid;-
133 if (stable) {
stableDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 768 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-768
134 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);-
135 if (idx >= 0)
idx >= 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2
136 return sk_ASN1_STRING_TABLE_value(stable, idx);
executed 2 times by 1 test: return sk_ASN1_STRING_TABLE_value(stable, idx);
Executed by:
  • libcrypto.so.1.1
2
137 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
138 return OBJ_bsearch_table(&fnd, tbl_standard, OSSL_NELEM(tbl_standard));
executed 770 times by 1 test: return OBJ_bsearch_table(&fnd, tbl_standard, (sizeof(tbl_standard)/sizeof((tbl_standard)[0])));
Executed by:
  • libcrypto.so.1.1
770
139}-
140-
141/*-
142 * Return a string table pointer which can be modified: either directly from-
143 * table or a copy of an internal value added to the table.-
144 */-
145-
146static ASN1_STRING_TABLE *stable_get(int nid)-
147{-
148 ASN1_STRING_TABLE *tmp, *rv;-
149-
150 /* Always need a string table so allocate one if NULL */-
151 if (stable == NULL) {
stable == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1
152 stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);-
153 if (stable == NULL)
stable == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
154 return NULL;
never executed: return ((void *)0) ;
0
155 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
156 tmp = ASN1_STRING_TABLE_get(nid);-
157 if (tmp != NULL && tmp->flags & STABLE_FLAGS_MALLOC)
tmp != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
tmp->flags & 0x01Description
TRUEnever evaluated
FALSEnever evaluated
0-2
158 return tmp;
never executed: return tmp;
0
159 if ((rv = OPENSSL_zalloc(sizeof(*rv))) == NULL) {
(rv = CRYPTO_z...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
160 ASN1err(ASN1_F_STABLE_GET, ERR_R_MALLOC_FAILURE);-
161 return NULL;
never executed: return ((void *)0) ;
0
162 }-
163 if (!sk_ASN1_STRING_TABLE_push(stable, rv)) {
!sk_ASN1_STRIN...sh(stable, rv)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
164 OPENSSL_free(rv);-
165 return NULL;
never executed: return ((void *)0) ;
0
166 }-
167 if (tmp != NULL) {
tmp != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
168 rv->nid = tmp->nid;-
169 rv->minsize = tmp->minsize;-
170 rv->maxsize = tmp->maxsize;-
171 rv->mask = tmp->mask;-
172 rv->flags = tmp->flags | STABLE_FLAGS_MALLOC;-
173 } else {
never executed: end of block
0
174 rv->nid = nid;-
175 rv->minsize = -1;-
176 rv->maxsize = -1;-
177 rv->flags = STABLE_FLAGS_MALLOC;-
178 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
179 return rv;
executed 2 times by 1 test: return rv;
Executed by:
  • libcrypto.so.1.1
2
180}-
181-
182int ASN1_STRING_TABLE_add(int nid,-
183 long minsize, long maxsize, unsigned long mask,-
184 unsigned long flags)-
185{-
186 ASN1_STRING_TABLE *tmp;-
187-
188 tmp = stable_get(nid);-
189 if (tmp == NULL) {
tmp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
190 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);-
191 return 0;
never executed: return 0;
0
192 }-
193 if (minsize >= 0)
minsize >= 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
194 tmp->minsize = minsize;
never executed: tmp->minsize = minsize;
0
195 if (maxsize >= 0)
maxsize >= 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
196 tmp->maxsize = maxsize;
never executed: tmp->maxsize = maxsize;
0
197 if (mask)
maskDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
198 tmp->mask = mask;
executed 2 times by 1 test: tmp->mask = mask;
Executed by:
  • libcrypto.so.1.1
2
199 if (flags)
flagsDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
200 tmp->flags = STABLE_FLAGS_MALLOC | flags;
never executed: tmp->flags = 0x01 | flags;
0
201 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
202}-
203-
204void ASN1_STRING_TABLE_cleanup(void)-
205{-
206 STACK_OF(ASN1_STRING_TABLE) *tmp;-
207-
208 tmp = stable;-
209 if (tmp == NULL)
tmp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
210 return;
never executed: return;
0
211 stable = NULL;-
212 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);-
213}
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
214-
215static void st_free(ASN1_STRING_TABLE *tbl)-
216{-
217 if (tbl->flags & STABLE_FLAGS_MALLOC)
tbl->flags & 0x01Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
218 OPENSSL_free(tbl);
executed 2 times by 1 test: CRYPTO_free(tbl, __FILE__, 218);
Executed by:
  • libcrypto.so.1.1
2
219}
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2