Bug Summary

File:out/../deps/openssl/openssl/crypto/core_namemap.c
Warning:line 401, column 9
Value stored to 'num' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name core_namemap.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D OPENSSL_NO_HW -D OPENSSL_API_COMPAT=0x10100001L -D STATIC_LEGACY -D NDEBUG -D OPENSSL_USE_NODELETE -D L_ENDIAN -D OPENSSL_BUILDING_OPENSSL -D AES_ASM -D BSAES_ASM -D CMLL_ASM -D ECP_NISTZ256_ASM -D GHASH_ASM -D KECCAK1600_ASM -D MD5_ASM -D OPENSSL_BN_ASM_GF2m -D OPENSSL_BN_ASM_MONT -D OPENSSL_BN_ASM_MONT5 -D OPENSSL_CPUID_OBJ -D OPENSSL_IA32_SSE2 -D PADLOCK_ASM -D POLY1305_ASM -D SHA1_ASM -D SHA256_ASM -D SHA512_ASM -D VPAES_ASM -D WHIRLPOOL_ASM -D X25519_ASM -D OPENSSL_PIC -D MODULESDIR="/home/maurizio/node-v18.6.0/out/Release/obj.target/deps/openssl/lib/openssl-modules" -D OPENSSLDIR="/home/maurizio/node-v18.6.0/out/Release/obj.target/deps/openssl" -D OPENSSLDIR="/etc/ssl" -D ENGINESDIR="/dev/null" -D TERMIOS -I ../deps/openssl/openssl -I ../deps/openssl/openssl/include -I ../deps/openssl/openssl/crypto -I ../deps/openssl/openssl/crypto/include -I ../deps/openssl/openssl/crypto/modes -I ../deps/openssl/openssl/crypto/ec/curve448 -I ../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I ../deps/openssl/openssl/providers/common/include -I ../deps/openssl/openssl/providers/implementations/include -I ../deps/openssl/config -I ../deps/openssl/config/archs/linux-x86_64/asm -I ../deps/openssl/config/archs/linux-x86_64/asm/include -I ../deps/openssl/config/archs/linux-x86_64/asm/crypto -I ../deps/openssl/config/archs/linux-x86_64/asm/crypto/include/internal -I ../deps/openssl/config/archs/linux-x86_64/asm/providers/common/include -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-missing-field-initializers -Wno-old-style-declaration -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c ../deps/openssl/openssl/crypto/core_namemap.c
1/*
2 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (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 "internal/namemap.h"
11#include <openssl/lhash.h>
12#include "crypto/lhash.h" /* ossl_lh_strcasehash */
13#include "internal/tsan_assist.h"
14#include "internal/sizes.h"
15
16/*-
17 * The namenum entry
18 * =================
19 */
20typedef struct {
21 char *name;
22 int number;
23} NAMENUM_ENTRY;
24
25DEFINE_LHASH_OF(NAMENUM_ENTRY)struct lhash_st_NAMENUM_ENTRY { union lh_NAMENUM_ENTRY_dummy {
void* d1; unsigned long d2; int d3; } dummy; }; static __attribute__
((unused)) inline struct lhash_st_NAMENUM_ENTRY *lh_NAMENUM_ENTRY_new
(unsigned long (*hfn)(const NAMENUM_ENTRY *), int (*cfn)(const
NAMENUM_ENTRY *, const NAMENUM_ENTRY *)) { return (struct lhash_st_NAMENUM_ENTRY
*) OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC
)cfn); } static __attribute__((unused)) inline void lh_NAMENUM_ENTRY_free
(struct lhash_st_NAMENUM_ENTRY *lh) { OPENSSL_LH_free((OPENSSL_LHASH
*)lh); } static __attribute__((unused)) inline void lh_NAMENUM_ENTRY_flush
(struct lhash_st_NAMENUM_ENTRY *lh) { OPENSSL_LH_flush((OPENSSL_LHASH
*)lh); } static __attribute__((unused)) inline NAMENUM_ENTRY
*lh_NAMENUM_ENTRY_insert(struct lhash_st_NAMENUM_ENTRY *lh, NAMENUM_ENTRY
*d) { return (NAMENUM_ENTRY *)OPENSSL_LH_insert((OPENSSL_LHASH
*)lh, d); } static __attribute__((unused)) inline NAMENUM_ENTRY
*lh_NAMENUM_ENTRY_delete(struct lhash_st_NAMENUM_ENTRY *lh, const
NAMENUM_ENTRY *d) { return (NAMENUM_ENTRY *)OPENSSL_LH_delete
((OPENSSL_LHASH *)lh, d); } static __attribute__((unused)) inline
NAMENUM_ENTRY *lh_NAMENUM_ENTRY_retrieve(struct lhash_st_NAMENUM_ENTRY
*lh, const NAMENUM_ENTRY *d) { return (NAMENUM_ENTRY *)OPENSSL_LH_retrieve
((OPENSSL_LHASH *)lh, d); } static __attribute__((unused)) inline
int lh_NAMENUM_ENTRY_error(struct lhash_st_NAMENUM_ENTRY *lh
) { return OPENSSL_LH_error((OPENSSL_LHASH *)lh); } static __attribute__
((unused)) inline unsigned long lh_NAMENUM_ENTRY_num_items(struct
lhash_st_NAMENUM_ENTRY *lh) { return OPENSSL_LH_num_items((OPENSSL_LHASH
*)lh); } static __attribute__((unused)) inline void lh_NAMENUM_ENTRY_node_stats_bio
(const struct lhash_st_NAMENUM_ENTRY *lh, BIO *out) { OPENSSL_LH_node_stats_bio
((const OPENSSL_LHASH *)lh, out); } static __attribute__((unused
)) inline void lh_NAMENUM_ENTRY_node_usage_stats_bio(const struct
lhash_st_NAMENUM_ENTRY *lh, BIO *out) { OPENSSL_LH_node_usage_stats_bio
((const OPENSSL_LHASH *)lh, out); } static __attribute__((unused
)) inline void lh_NAMENUM_ENTRY_stats_bio(const struct lhash_st_NAMENUM_ENTRY
*lh, BIO *out) { OPENSSL_LH_stats_bio((const OPENSSL_LHASH *
)lh, out); } static __attribute__((unused)) inline unsigned long
lh_NAMENUM_ENTRY_get_down_load(struct lhash_st_NAMENUM_ENTRY
*lh) { return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh);
} static __attribute__((unused)) inline void lh_NAMENUM_ENTRY_set_down_load
(struct lhash_st_NAMENUM_ENTRY *lh, unsigned long dl) { OPENSSL_LH_set_down_load
((OPENSSL_LHASH *)lh, dl); } static __attribute__((unused)) inline
void lh_NAMENUM_ENTRY_doall(struct lhash_st_NAMENUM_ENTRY *lh
, void (*doall)(NAMENUM_ENTRY *)) { OPENSSL_LH_doall((OPENSSL_LHASH
*)lh, (OPENSSL_LH_DOALL_FUNC)doall); } static __attribute__(
(unused)) inline void lh_NAMENUM_ENTRY_doall_arg(struct lhash_st_NAMENUM_ENTRY
*lh, void (*doallarg)(NAMENUM_ENTRY *, void *), void *arg) {
OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG
)doallarg, arg); } struct lhash_st_NAMENUM_ENTRY
;
26
27/*-
28 * The namemap itself
29 * ==================
30 */
31
32struct ossl_namemap_st {
33 /* Flags */
34 unsigned int stored:1; /* If 1, it's stored in a library context */
35
36 CRYPTO_RWLOCK *lock;
37 LHASH_OF(NAMENUM_ENTRY)struct lhash_st_NAMENUM_ENTRY *namenum; /* Name->number mapping */
38
39 TSAN_QUALIFIER_Atomic int max_number; /* Current max number */
40};
41
42/* LHASH callbacks */
43
44static unsigned long namenum_hash(const NAMENUM_ENTRY *n)
45{
46 return ossl_lh_strcasehash(n->name);
47}
48
49static int namenum_cmp(const NAMENUM_ENTRY *a, const NAMENUM_ENTRY *b)
50{
51 return OPENSSL_strcasecmp(a->name, b->name);
52}
53
54static void namenum_free(NAMENUM_ENTRY *n)
55{
56 if (n != NULL((void*)0))
57 OPENSSL_free(n->name)CRYPTO_free(n->name, "../deps/openssl/openssl/crypto/core_namemap.c"
, 57)
;
58 OPENSSL_free(n)CRYPTO_free(n, "../deps/openssl/openssl/crypto/core_namemap.c"
, 58)
;
59}
60
61/* OSSL_LIB_CTX_METHOD functions for a namemap stored in a library context */
62
63static void *stored_namemap_new(OSSL_LIB_CTX *libctx)
64{
65 OSSL_NAMEMAP *namemap = ossl_namemap_new();
66
67 if (namemap != NULL((void*)0))
68 namemap->stored = 1;
69
70 return namemap;
71}
72
73static void stored_namemap_free(void *vnamemap)
74{
75 OSSL_NAMEMAP *namemap = vnamemap;
76
77 if (namemap != NULL((void*)0)) {
78 /* Pretend it isn't stored, or ossl_namemap_free() will do nothing */
79 namemap->stored = 0;
80 ossl_namemap_free(namemap);
81 }
82}
83
84static const OSSL_LIB_CTX_METHOD stored_namemap_method = {
85 OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY0,
86 stored_namemap_new,
87 stored_namemap_free,
88};
89
90/*-
91 * API functions
92 * =============
93 */
94
95int ossl_namemap_empty(OSSL_NAMEMAP *namemap)
96{
97#ifdef TSAN_REQUIRES_LOCKING
98 /* No TSAN support */
99 int rv;
100
101 if (namemap == NULL((void*)0))
102 return 1;
103
104 if (!CRYPTO_THREAD_read_lock(namemap->lock))
105 return -1;
106 rv = namemap->max_number == 0;
107 CRYPTO_THREAD_unlock(namemap->lock);
108 return rv;
109#else
110 /* Have TSAN support */
111 return namemap == NULL((void*)0) || tsan_load(&namemap->max_number)__c11_atomic_load((&namemap->max_number), memory_order_relaxed
)
== 0;
112#endif
113}
114
115typedef struct doall_names_data_st {
116 int number;
117 const char **names;
118 int found;
119} DOALL_NAMES_DATA;
120
121static void do_name(const NAMENUM_ENTRY *namenum, DOALL_NAMES_DATA *data)
122{
123 if (namenum->number == data->number)
124 data->names[data->found++] = namenum->name;
125}
126
127IMPLEMENT_LHASH_DOALL_ARG_CONST(NAMENUM_ENTRY, DOALL_NAMES_DATA)static __attribute__((unused)) inline void lh_NAMENUM_ENTRY_doall_DOALL_NAMES_DATA
(struct lhash_st_NAMENUM_ENTRY *lh, void (*fn)(const NAMENUM_ENTRY
*, DOALL_NAMES_DATA *), DOALL_NAMES_DATA *arg) { OPENSSL_LH_doall_arg
((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg
); } struct lhash_st_NAMENUM_ENTRY
;
128
129/*
130 * Call the callback for all names in the namemap with the given number.
131 * A return value 1 means that the callback was called for all names. A
132 * return value of 0 means that the callback was not called for any names.
133 */
134int ossl_namemap_doall_names(const OSSL_NAMEMAP *namemap, int number,
135 void (*fn)(const char *name, void *data),
136 void *data)
137{
138 DOALL_NAMES_DATA cbdata;
139 size_t num_names;
140 int i;
141
142 cbdata.number = number;
143 cbdata.found = 0;
144
145 /*
146 * We collect all the names first under a read lock. Subsequently we call
147 * the user function, so that we're not holding the read lock when in user
148 * code. This could lead to deadlocks.
149 */
150 if (!CRYPTO_THREAD_read_lock(namemap->lock))
151 return 0;
152
153 num_names = lh_NAMENUM_ENTRY_num_items(namemap->namenum);
154 if (num_names == 0) {
155 CRYPTO_THREAD_unlock(namemap->lock);
156 return 0;
157 }
158 cbdata.names = OPENSSL_malloc(sizeof(*cbdata.names) * num_names)CRYPTO_malloc(sizeof(*cbdata.names) * num_names, "../deps/openssl/openssl/crypto/core_namemap.c"
, 158)
;
159 if (cbdata.names == NULL((void*)0)) {
160 CRYPTO_THREAD_unlock(namemap->lock);
161 return 0;
162 }
163 lh_NAMENUM_ENTRY_doall_DOALL_NAMES_DATA(namemap->namenum, do_name,
164 &cbdata);
165 CRYPTO_THREAD_unlock(namemap->lock);
166
167 for (i = 0; i < cbdata.found; i++)
168 fn(cbdata.names[i], data);
169
170 OPENSSL_free(cbdata.names)CRYPTO_free(cbdata.names, "../deps/openssl/openssl/crypto/core_namemap.c"
, 170)
;
171 return 1;
172}
173
174static int namemap_name2num_n(const OSSL_NAMEMAP *namemap,
175 const char *name, size_t name_len)
176{
177 NAMENUM_ENTRY *namenum_entry, namenum_tmpl;
178
179 if ((namenum_tmpl.name = OPENSSL_strndup(name, name_len)CRYPTO_strndup(name, name_len, "../deps/openssl/openssl/crypto/core_namemap.c"
, 179)
) == NULL((void*)0))
180 return 0;
181 namenum_tmpl.number = 0;
182 namenum_entry =
183 lh_NAMENUM_ENTRY_retrieve(namemap->namenum, &namenum_tmpl);
184 OPENSSL_free(namenum_tmpl.name)CRYPTO_free(namenum_tmpl.name, "../deps/openssl/openssl/crypto/core_namemap.c"
, 184)
;
185 return namenum_entry != NULL((void*)0) ? namenum_entry->number : 0;
186}
187
188int ossl_namemap_name2num_n(const OSSL_NAMEMAP *namemap,
189 const char *name, size_t name_len)
190{
191 int number;
192
193#ifndef FIPS_MODULE
194 if (namemap == NULL((void*)0))
195 namemap = ossl_namemap_stored(NULL((void*)0));
196#endif
197
198 if (namemap == NULL((void*)0))
199 return 0;
200
201 if (!CRYPTO_THREAD_read_lock(namemap->lock))
202 return 0;
203 number = namemap_name2num_n(namemap, name, name_len);
204 CRYPTO_THREAD_unlock(namemap->lock);
205
206 return number;
207}
208
209int ossl_namemap_name2num(const OSSL_NAMEMAP *namemap, const char *name)
210{
211 if (name == NULL((void*)0))
212 return 0;
213
214 return ossl_namemap_name2num_n(namemap, name, strlen(name));
215}
216
217struct num2name_data_st {
218 size_t idx; /* Countdown */
219 const char *name; /* Result */
220};
221
222static void do_num2name(const char *name, void *vdata)
223{
224 struct num2name_data_st *data = vdata;
225
226 if (data->idx > 0)
227 data->idx--;
228 else if (data->name == NULL((void*)0))
229 data->name = name;
230}
231
232const char *ossl_namemap_num2name(const OSSL_NAMEMAP *namemap, int number,
233 size_t idx)
234{
235 struct num2name_data_st data;
236
237 data.idx = idx;
238 data.name = NULL((void*)0);
239 if (!ossl_namemap_doall_names(namemap, number, do_num2name, &data))
240 return NULL((void*)0);
241 return data.name;
242}
243
244static int namemap_add_name_n(OSSL_NAMEMAP *namemap, int number,
245 const char *name, size_t name_len)
246{
247 NAMENUM_ENTRY *namenum = NULL((void*)0);
248 int tmp_number;
249
250 /* If it already exists, we don't add it */
251 if ((tmp_number = namemap_name2num_n(namemap, name, name_len)) != 0)
252 return tmp_number;
253
254 if ((namenum = OPENSSL_zalloc(sizeof(*namenum))CRYPTO_zalloc(sizeof(*namenum), "../deps/openssl/openssl/crypto/core_namemap.c"
, 254)
) == NULL((void*)0)
255 || (namenum->name = OPENSSL_strndup(name, name_len)CRYPTO_strndup(name, name_len, "../deps/openssl/openssl/crypto/core_namemap.c"
, 255)
) == NULL((void*)0))
256 goto err;
257
258 /* The tsan_counter use here is safe since we're under lock */
259 namenum->number =
260 number != 0 ? number : 1 + tsan_counter(&namemap->max_number)__c11_atomic_fetch_add((&namemap->max_number), 1, memory_order_relaxed
)
;
261 (void)lh_NAMENUM_ENTRY_insert(namemap->namenum, namenum);
262
263 if (lh_NAMENUM_ENTRY_error(namemap->namenum))
264 goto err;
265 return namenum->number;
266
267 err:
268 namenum_free(namenum);
269 return 0;
270}
271
272int ossl_namemap_add_name_n(OSSL_NAMEMAP *namemap, int number,
273 const char *name, size_t name_len)
274{
275 int tmp_number;
276
277#ifndef FIPS_MODULE
278 if (namemap == NULL((void*)0))
279 namemap = ossl_namemap_stored(NULL((void*)0));
280#endif
281
282 if (name == NULL((void*)0) || name_len == 0 || namemap == NULL((void*)0))
283 return 0;
284
285 if (!CRYPTO_THREAD_write_lock(namemap->lock))
286 return 0;
287 tmp_number = namemap_add_name_n(namemap, number, name, name_len);
288 CRYPTO_THREAD_unlock(namemap->lock);
289 return tmp_number;
290}
291
292int ossl_namemap_add_name(OSSL_NAMEMAP *namemap, int number, const char *name)
293{
294 if (name == NULL((void*)0))
295 return 0;
296
297 return ossl_namemap_add_name_n(namemap, number, name, strlen(name));
298}
299
300int ossl_namemap_add_names(OSSL_NAMEMAP *namemap, int number,
301 const char *names, const char separator)
302{
303 const char *p, *q;
304 size_t l;
305
306 /* Check that we have a namemap */
307 if (!ossl_assert(namemap != NULL)((namemap != ((void*)0)) != 0)) {
308 ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/core_namemap.c"
,308,__func__), ERR_set_error)((15),((258|((0x1 << 18L)
|(0x2 << 18L)))),((void*)0))
;
309 return 0;
310 }
311
312 if (!CRYPTO_THREAD_write_lock(namemap->lock))
313 return 0;
314 /*
315 * Check that no name is an empty string, and that all names have at
316 * most one numeric identity together.
317 */
318 for (p = names; *p != '\0'; p = (q == NULL((void*)0) ? p + l : q + 1)) {
319 int this_number;
320
321 if ((q = strchr(p, separator)) == NULL((void*)0))
322 l = strlen(p); /* offset to \0 */
323 else
324 l = q - p; /* offset to the next separator */
325
326 this_number = namemap_name2num_n(namemap, p, l);
327
328 if (*p == '\0' || *p == separator) {
329 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_BAD_ALGORITHM_NAME)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/core_namemap.c"
,329,__func__), ERR_set_error)((15),(117),((void*)0))
;
330 goto err;
331 }
332 if (number == 0) {
333 number = this_number;
334 } else if (this_number != 0 && this_number != number) {
335 ERR_raise_data(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/core_namemap.c"
,335,__func__), ERR_set_error)
(ERR_LIB_CRYPTO15, CRYPTO_R_CONFLICTING_NAMES118,
336 "\"%.*s\" has an existing different identity %d (from \"%s\")",
337 l, p, this_number, names);
338 goto err;
339 }
340 }
341
342 /* Now that we have checked, register all names */
343 for (p = names; *p != '\0'; p = (q == NULL((void*)0) ? p + l : q + 1)) {
344 int this_number;
345
346 if ((q = strchr(p, separator)) == NULL((void*)0))
347 l = strlen(p); /* offset to \0 */
348 else
349 l = q - p; /* offset to the next separator */
350
351 this_number = namemap_add_name_n(namemap, number, p, l);
352 if (number == 0) {
353 number = this_number;
354 } else if (this_number != number) {
355 ERR_raise_data(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/core_namemap.c"
,355,__func__), ERR_set_error)
(ERR_LIB_CRYPTO15, ERR_R_INTERNAL_ERROR(259|((0x1 << 18L)|(0x2 << 18L))),
356 "Got number %d when expecting %d",
357 this_number, number);
358 goto err;
359 }
360 }
361
362 CRYPTO_THREAD_unlock(namemap->lock);
363 return number;
364
365 err:
366 CRYPTO_THREAD_unlock(namemap->lock);
367 return 0;
368}
369
370/*-
371 * Pre-population
372 * ==============
373 */
374
375#ifndef FIPS_MODULE
376#include <openssl/evp.h>
377
378/* Creates an initial namemap with names found in the legacy method db */
379static void get_legacy_evp_names(int base_nid, int nid, const char *pem_name,
380 void *arg)
381{
382 int num = 0;
383 ASN1_OBJECT *obj;
384
385 if (base_nid != NID_undef0) {
386 num = ossl_namemap_add_name(arg, num, OBJ_nid2sn(base_nid));
387 num = ossl_namemap_add_name(arg, num, OBJ_nid2ln(base_nid));
388 }
389
390 if (nid != NID_undef0) {
391 num = ossl_namemap_add_name(arg, num, OBJ_nid2sn(nid));
392 num = ossl_namemap_add_name(arg, num, OBJ_nid2ln(nid));
393 if ((obj = OBJ_nid2obj(nid)) != NULL((void*)0)) {
394 char txtoid[OSSL_MAX_NAME_SIZE50];
395
396 if (OBJ_obj2txt(txtoid, sizeof(txtoid), obj, 1) > 0)
397 num = ossl_namemap_add_name(arg, num, txtoid);
398 }
399 }
400 if (pem_name != NULL((void*)0))
401 num = ossl_namemap_add_name(arg, num, pem_name);
Value stored to 'num' is never read
402}
403
404static void get_legacy_cipher_names(const OBJ_NAME *on, void *arg)
405{
406 const EVP_CIPHER *cipher = (void *)OBJ_NAME_get(on->name, on->type);
407
408 if (cipher != NULL((void*)0))
409 get_legacy_evp_names(NID_undef0, EVP_CIPHER_get_type(cipher), NULL((void*)0), arg);
410}
411
412static void get_legacy_md_names(const OBJ_NAME *on, void *arg)
413{
414 const EVP_MD *md = (void *)OBJ_NAME_get(on->name, on->type);
415
416 if (md != NULL((void*)0))
417 get_legacy_evp_names(0, EVP_MD_get_type(md), NULL((void*)0), arg);
418}
419
420static void get_legacy_pkey_meth_names(const EVP_PKEY_ASN1_METHOD *ameth,
421 void *arg)
422{
423 int nid = 0, base_nid = 0, flags = 0;
424 const char *pem_name = NULL((void*)0);
425
426 EVP_PKEY_asn1_get0_info(&nid, &base_nid, &flags, NULL((void*)0), &pem_name, ameth);
427 if (nid != NID_undef0) {
428 if ((flags & ASN1_PKEY_ALIAS0x1) == 0) {
429 switch (nid) {
430 case EVP_PKEY_DHX920:
431 /* We know that the name "DHX" is used too */
432 get_legacy_evp_names(0, nid, "DHX", arg);
433 /* FALLTHRU */
434 default:
435 get_legacy_evp_names(0, nid, pem_name, arg);
436 }
437 } else {
438 /*
439 * Treat aliases carefully, some of them are undesirable, or
440 * should not be treated as such for providers.
441 */
442
443 switch (nid) {
444 case EVP_PKEY_SM21172:
445 /*
446 * SM2 is a separate keytype with providers, not an alias for
447 * EC.
448 */
449 get_legacy_evp_names(0, nid, pem_name, arg);
450 break;
451 default:
452 /* Use the short name of the base nid as the common reference */
453 get_legacy_evp_names(base_nid, nid, pem_name, arg);
454 }
455 }
456 }
457}
458#endif
459
460/*-
461 * Constructors / destructors
462 * ==========================
463 */
464
465OSSL_NAMEMAP *ossl_namemap_stored(OSSL_LIB_CTX *libctx)
466{
467#ifndef FIPS_MODULE
468 int nms;
469#endif
470 OSSL_NAMEMAP *namemap =
471 ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_NAMEMAP_INDEX4,
472 &stored_namemap_method);
473
474 if (namemap == NULL((void*)0))
475 return NULL((void*)0);
476
477#ifndef FIPS_MODULE
478 nms = ossl_namemap_empty(namemap);
479 if (nms < 0) {
480 /*
481 * Could not get lock to make the count, so maybe internal objects
482 * weren't added. This seems safest.
483 */
484 return NULL((void*)0);
485 }
486 if (nms == 1) {
487 int i, end;
488
489 /* Before pilfering, we make sure the legacy database is populated */
490 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS0x00000004L
491 | OPENSSL_INIT_ADD_ALL_DIGESTS0x00000008L, NULL((void*)0));
492
493 OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH0x02,
494 get_legacy_cipher_names, namemap);
495 OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH0x01,
496 get_legacy_md_names, namemap);
497
498 /* We also pilfer data from the legacy EVP_PKEY_ASN1_METHODs */
499 for (i = 0, end = EVP_PKEY_asn1_get_count(); i < end; i++)
500 get_legacy_pkey_meth_names(EVP_PKEY_asn1_get0(i), namemap);
501 }
502#endif
503
504 return namemap;
505}
506
507OSSL_NAMEMAP *ossl_namemap_new(void)
508{
509 OSSL_NAMEMAP *namemap;
510
511 if ((namemap = OPENSSL_zalloc(sizeof(*namemap))CRYPTO_zalloc(sizeof(*namemap), "../deps/openssl/openssl/crypto/core_namemap.c"
, 511)
) != NULL((void*)0)
512 && (namemap->lock = CRYPTO_THREAD_lock_new()) != NULL((void*)0)
513 && (namemap->namenum =
514 lh_NAMENUM_ENTRY_new(namenum_hash, namenum_cmp)) != NULL((void*)0))
515 return namemap;
516
517 ossl_namemap_free(namemap);
518 return NULL((void*)0);
519}
520
521void ossl_namemap_free(OSSL_NAMEMAP *namemap)
522{
523 if (namemap == NULL((void*)0) || namemap->stored)
524 return;
525
526 lh_NAMENUM_ENTRY_doall(namemap->namenum, namenum_free);
527 lh_NAMENUM_ENTRY_free(namemap->namenum);
528
529 CRYPTO_THREAD_lock_free(namemap->lock);
530 OPENSSL_free(namemap)CRYPTO_free(namemap, "../deps/openssl/openssl/crypto/core_namemap.c"
, 530)
;
531}