OpenCoverage

conf_api.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/conf/conf_api.c
Source codeSwitch to Preprocessed file
LineSourceCount
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/* Part of the code in here was originally in conf.c, which is now removed */-
11-
12#include "e_os.h"-
13#include <stdlib.h>-
14#include <string.h>-
15#include <openssl/conf.h>-
16#include <openssl/conf_api.h>-
17-
18static void value_free_hash(const CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf);-
19static void value_free_stack_doall(CONF_VALUE *a);-
20-
21/* Up until OpenSSL 0.9.5a, this was get_section */-
22CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)-
23{-
24 CONF_VALUE *v, vv;-
25-
26 if ((conf == NULL) || (section == NULL))
(conf == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 40177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(section == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 40177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-40177
27 return NULL;
never executed: return ((void *)0) ;
0
28 vv.name = NULL;-
29 vv.section = (char *)section;-
30 v = lh_CONF_VALUE_retrieve(conf->data, &vv);-
31 return v;
executed 40177 times by 1 test: return v;
Executed by:
  • libcrypto.so.1.1
40177
32}-
33-
34/* Up until OpenSSL 0.9.5a, this was CONF_get_section */-
35STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,-
36 const char *section)-
37{-
38 CONF_VALUE *v;-
39-
40 v = _CONF_get_section(conf, section);-
41 if (v != NULL)
v != ((void *)0)Description
TRUEevaluated 6085 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6085
42 return ((STACK_OF(CONF_VALUE) *)v->value);
executed 6085 times by 1 test: return ((struct stack_st_CONF_VALUE *)v->value);
Executed by:
  • libcrypto.so.1.1
6085
43 else-
44 return NULL;
never executed: return ((void *)0) ;
0
45}-
46-
47int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)-
48{-
49 CONF_VALUE *v = NULL;-
50 STACK_OF(CONF_VALUE) *ts;-
51-
52 ts = (STACK_OF(CONF_VALUE) *)section->value;-
53-
54 value->section = section->section;-
55 if (!sk_CONF_VALUE_push(ts, value)) {
!sk_CONF_VALUE_push(ts, value)Description
TRUEnever evaluated
FALSEevaluated 86981 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-86981
56 return 0;
never executed: return 0;
0
57 }-
58-
59 v = lh_CONF_VALUE_insert(conf->data, value);-
60 if (v != NULL) {
v != ((void *)0)Description
TRUEevaluated 12854 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 74127 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
12854-74127
61 (void)sk_CONF_VALUE_delete_ptr(ts, v);-
62 OPENSSL_free(v->name);-
63 OPENSSL_free(v->value);-
64 OPENSSL_free(v);-
65 }
executed 12854 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12854
66 return 1;
executed 86981 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
86981
67}-
68-
69char *_CONF_get_string(const CONF *conf, const char *section,-
70 const char *name)-
71{-
72 CONF_VALUE *v, vv;-
73 char *p;-
74-
75 if (name == NULL)
name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45451 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45451
76 return NULL;
never executed: return ((void *)0) ;
0
77 if (conf != NULL) {
conf != ((void *)0)Description
TRUEevaluated 45451 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-45451
78 if (section != NULL) {
section != ((void *)0)Description
TRUEevaluated 42591 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2860 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2860-42591
79 vv.name = (char *)name;-
80 vv.section = (char *)section;-
81 v = lh_CONF_VALUE_retrieve(conf->data, &vv);-
82 if (v != NULL)
v != ((void *)0)Description
TRUEevaluated 34885 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 7706 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
7706-34885
83 return v->value;
executed 34885 times by 1 test: return v->value;
Executed by:
  • libcrypto.so.1.1
34885
84 if (strcmp(section, "ENV") == 0) {
never executed: __result = (((const unsigned char *) (const char *) ( section ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
executed 5591 times by 1 test: __result = (((const unsigned char *) (const char *) ( "ENV" ))[3] - __s2[3]);
Executed by:
  • libcrypto.so.1.1
executed 6224 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
executed 6338 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
__extension__ ... )))); }) == 0Description
TRUEevaluated 4783 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2923 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
TRUEevaluated 7706 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
__result == 0Description
TRUEevaluated 6338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1368 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
__s2_len > 1Description
TRUEevaluated 6338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
__result == 0Description
TRUEevaluated 6224 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 114 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
__s2_len > 2Description
TRUEevaluated 6224 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
__result == 0Description
TRUEevaluated 5591 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-7706
85 p = getenv(name);-
86 if (p != NULL)
p != ((void *)0)Description
TRUEevaluated 4135 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 648 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
648-4135
87 return p;
executed 4135 times by 1 test: return p;
Executed by:
  • libcrypto.so.1.1
4135
88 }
executed 648 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
648
89 }
executed 3571 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3571
90 vv.section = "default";-
91 vv.name = (char *)name;-
92 v = lh_CONF_VALUE_retrieve(conf->data, &vv);-
93 if (v != NULL)
v != ((void *)0)Description
TRUEevaluated 6010 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 421 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
421-6010
94 return v->value;
executed 6010 times by 1 test: return v->value;
Executed by:
  • libcrypto.so.1.1
6010
95 else-
96 return NULL;
executed 421 times by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
421
97 } else-
98 return getenv(name);
never executed: return getenv(name);
0
99}-
100-
101static unsigned long conf_value_hash(const CONF_VALUE *v)-
102{-
103 return (OPENSSL_LH_strhash(v->section) << 2) ^ OPENSSL_LH_strhash(v->name);
executed 283523 times by 1 test: return (OPENSSL_LH_strhash(v->section) << 2) ^ OPENSSL_LH_strhash(v->name);
Executed by:
  • libcrypto.so.1.1
283523
104}-
105-
106static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b)-
107{-
108 int i;-
109-
110 if (a->section != b->section) {
a->section != b->sectionDescription
TRUEevaluated 58577 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 104233 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
58577-104233
111 i = strcmp(a->section, b->section);
never executed: __result = (((const unsigned char *) (const char *) ( a->section ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( b->section ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__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
112 if (i)
iDescription
TRUEevaluated 586 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 57991 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
586-57991
113 return i;
executed 586 times by 1 test: return i;
Executed by:
  • libcrypto.so.1.1
586
114 }
executed 57991 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
57991
115-
116 if ((a->name != NULL) && (b->name != NULL)) {
(a->name != ((void *)0) )Description
TRUEevaluated 129026 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 33198 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(b->name != ((void *)0) )Description
TRUEevaluated 128360 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 666 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
666-129026
117 i = strcmp(a->name, b->name);
never executed: __result = (((const unsigned char *) (const char *) ( a->name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( b->name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__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
118 return i;
executed 128360 times by 1 test: return i;
Executed by:
  • libcrypto.so.1.1
128360
119 } else if (a->name == b->name)
a->name == b->nameDescription
TRUEevaluated 9111 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 24753 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9111-24753
120 return 0;
executed 9111 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
9111
121 else-
122 return ((a->name == NULL) ? -1 : 1);
executed 24753 times by 1 test: return ((a->name == ((void *)0) ) ? -1 : 1);
Executed by:
  • libcrypto.so.1.1
(a->name == ((void *)0) )Description
TRUEevaluated 24087 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 666 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
666-24753
123}-
124-
125int _CONF_new_data(CONF *conf)-
126{-
127 if (conf == NULL) {
conf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2150 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2150
128 return 0;
never executed: return 0;
0
129 }-
130 if (conf->data == NULL) {
conf->data == ((void *)0)Description
TRUEevaluated 2150 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2150
131 conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);-
132 if (conf->data == NULL)
conf->data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2150 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2150
133 return 0;
never executed: return 0;
0
134 }
executed 2150 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2150
135 return 1;
executed 2150 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2150
136}-
137-
138typedef LHASH_OF(CONF_VALUE) LH_CONF_VALUE;-
139-
140IMPLEMENT_LHASH_DOALL_ARG_CONST(CONF_VALUE, LH_CONF_VALUE);
executed 2150 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2150
141-
142void _CONF_free_data(CONF *conf)-
143{-
144 if (conf == NULL || conf->data == NULL)
conf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4468 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
conf->data == ((void *)0)Description
TRUEevaluated 2318 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2150 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4468
145 return;
executed 2318 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
2318
146-
147 /* evil thing to make sure the 'OPENSSL_free()' works as expected */-
148 lh_CONF_VALUE_set_down_load(conf->data, 0);-
149 lh_CONF_VALUE_doall_LH_CONF_VALUE(conf->data, value_free_hash, conf->data);-
150-
151 /*-
152 * We now have only 'section' entries in the hash table. Due to problems-
153 * with-
154 */-
155-
156 lh_CONF_VALUE_doall(conf->data, value_free_stack_doall);-
157 lh_CONF_VALUE_free(conf->data);-
158}
executed 2150 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2150
159-
160static void value_free_hash(const CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf)-
161{-
162 if (a->name != NULL)
a->name != ((void *)0)Description
TRUEevaluated 74127 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
33216-74127
163 (void)lh_CONF_VALUE_delete(conf, a);
executed 74127 times by 1 test: (void)lh_CONF_VALUE_delete(conf, a);
Executed by:
  • libcrypto.so.1.1
74127
164}
executed 107343 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
107343
165-
166static void value_free_stack_doall(CONF_VALUE *a)-
167{-
168 CONF_VALUE *vv;-
169 STACK_OF(CONF_VALUE) *sk;-
170 int i;-
171-
172 if (a->name != NULL)
a->name != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33216
173 return;
never executed: return;
0
174-
175 sk = (STACK_OF(CONF_VALUE) *)a->value;-
176 for (i = sk_CONF_VALUE_num(sk) - 1; i >= 0; i--) {
i >= 0Description
TRUEevaluated 74127 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
33216-74127
177 vv = sk_CONF_VALUE_value(sk, i);-
178 OPENSSL_free(vv->value);-
179 OPENSSL_free(vv->name);-
180 OPENSSL_free(vv);-
181 }
executed 74127 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
74127
182 sk_CONF_VALUE_free(sk);-
183 OPENSSL_free(a->section);-
184 OPENSSL_free(a);-
185}
executed 33216 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
33216
186-
187/* Up until OpenSSL 0.9.5a, this was new_section */-
188CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)-
189{-
190 STACK_OF(CONF_VALUE) *sk = NULL;-
191 int i;-
192 CONF_VALUE *v = NULL, *vv;-
193-
194 if ((sk = sk_CONF_VALUE_new_null()) == NULL)
(sk = sk_CONF_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33216
195 goto err;
never executed: goto err;
0
196 if ((v = OPENSSL_malloc(sizeof(*v))) == NULL)
(v = CRYPTO_ma...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33216
197 goto err;
never executed: goto err;
0
198 i = strlen(section) + 1;-
199 if ((v->section = OPENSSL_malloc(i)) == NULL)
(v->section = ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33216
200 goto err;
never executed: goto err;
0
201-
202 memcpy(v->section, section, i);-
203 v->name = NULL;-
204 v->value = (char *)sk;-
205-
206 vv = lh_CONF_VALUE_insert(conf->data, v);-
207 if (vv != NULL || lh_CONF_VALUE_error(conf->data) > 0)
vv != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
lh_CONF_VALUE_...onf->data) > 0Description
TRUEnever evaluated
FALSEevaluated 33216 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-33216
208 goto err;
never executed: goto err;
0
209 return v;
executed 33216 times by 1 test: return v;
Executed by:
  • libcrypto.so.1.1
33216
210-
211 err:-
212 sk_CONF_VALUE_free(sk);-
213 if (v != NULL)
v != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
214 OPENSSL_free(v->section);
never executed: CRYPTO_free(v->section, __FILE__, 214);
0
215 OPENSSL_free(v);-
216 return NULL;
never executed: return ((void *)0) ;
0
217}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2