Bug Summary

File:out/../deps/openssl/openssl/crypto/objects/obj_dat.c
Warning:line 534, column 13
Value stored to 'l' 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 obj_dat.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/objects/obj_dat.c
1/*
2 * Copyright 1995-2021 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 <stdio.h>
11#include "crypto/ctype.h"
12#include <limits.h>
13#include "internal/cryptlib.h"
14#include <openssl/lhash.h>
15#include <openssl/asn1.h>
16#include "crypto/objects.h"
17#include <openssl/bn.h>
18#include "crypto/asn1.h"
19#include "obj_local.h"
20
21/* obj_dat.h is generated from objects.h by obj_dat.pl */
22#include "obj_dat.h"
23
24DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn)static int sn_cmp_BSEARCH_CMP_FN(const void *, const void *);
static int sn_cmp(const ASN1_OBJECT * const *, unsigned int const
*); static unsigned int * OBJ_bsearch_sn(const ASN1_OBJECT *
*key, unsigned int const *base, int num)
;
25DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln)static int ln_cmp_BSEARCH_CMP_FN(const void *, const void *);
static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const
*); static unsigned int * OBJ_bsearch_ln(const ASN1_OBJECT *
*key, unsigned int const *base, int num)
;
26DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj)static int obj_cmp_BSEARCH_CMP_FN(const void *, const void *)
; static int obj_cmp(const ASN1_OBJECT * const *, unsigned int
const *); static unsigned int * OBJ_bsearch_obj(const ASN1_OBJECT
* *key, unsigned int const *base, int num)
;
27
28#define ADDED_DATA0 0
29#define ADDED_SNAME1 1
30#define ADDED_LNAME2 2
31#define ADDED_NID3 3
32
33struct added_obj_st {
34 int type;
35 ASN1_OBJECT *obj;
36};
37
38static int new_nid = NUM_NID1248;
39static LHASH_OF(ADDED_OBJ)struct lhash_st_ADDED_OBJ *added = NULL((void*)0);
40
41static int sn_cmp(const ASN1_OBJECT *const *a, const unsigned int *b)
42{
43 return strcmp((*a)->sn, nid_objs[*b].sn);
44}
45
46IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn)static int sn_cmp_BSEARCH_CMP_FN(const void *a_, const void *
b_) { const ASN1_OBJECT * const *a = a_; unsigned int const *
b = b_; return sn_cmp(a,b); } static unsigned int *OBJ_bsearch_sn
(const ASN1_OBJECT * *key, unsigned int const *base, int num)
{ return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof
(unsigned int), sn_cmp_BSEARCH_CMP_FN); } extern void dummy_prototype
(void)
;
47
48static int ln_cmp(const ASN1_OBJECT *const *a, const unsigned int *b)
49{
50 return strcmp((*a)->ln, nid_objs[*b].ln);
51}
52
53IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln)static int ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *
b_) { const ASN1_OBJECT * const *a = a_; unsigned int const *
b = b_; return ln_cmp(a,b); } static unsigned int *OBJ_bsearch_ln
(const ASN1_OBJECT * *key, unsigned int const *base, int num)
{ return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof
(unsigned int), ln_cmp_BSEARCH_CMP_FN); } extern void dummy_prototype
(void)
;
54
55static unsigned long added_obj_hash(const ADDED_OBJ *ca)
56{
57 const ASN1_OBJECT *a;
58 int i;
59 unsigned long ret = 0;
60 unsigned char *p;
61
62 a = ca->obj;
63 switch (ca->type) {
64 case ADDED_DATA0:
65 ret = a->length << 20L;
66 p = (unsigned char *)a->data;
67 for (i = 0; i < a->length; i++)
68 ret ^= p[i] << ((i * 3) % 24);
69 break;
70 case ADDED_SNAME1:
71 ret = OPENSSL_LH_strhash(a->sn);
72 break;
73 case ADDED_LNAME2:
74 ret = OPENSSL_LH_strhash(a->ln);
75 break;
76 case ADDED_NID3:
77 ret = a->nid;
78 break;
79 default:
80 /* abort(); */
81 return 0;
82 }
83 ret &= 0x3fffffffL;
84 ret |= ((unsigned long)ca->type) << 30L;
85 return ret;
86}
87
88static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
89{
90 ASN1_OBJECT *a, *b;
91 int i;
92
93 i = ca->type - cb->type;
94 if (i)
95 return i;
96 a = ca->obj;
97 b = cb->obj;
98 switch (ca->type) {
99 case ADDED_DATA0:
100 i = (a->length - b->length);
101 if (i)
102 return i;
103 return memcmp(a->data, b->data, (size_t)a->length);
104 case ADDED_SNAME1:
105 if (a->sn == NULL((void*)0))
106 return -1;
107 else if (b->sn == NULL((void*)0))
108 return 1;
109 else
110 return strcmp(a->sn, b->sn);
111 case ADDED_LNAME2:
112 if (a->ln == NULL((void*)0))
113 return -1;
114 else if (b->ln == NULL((void*)0))
115 return 1;
116 else
117 return strcmp(a->ln, b->ln);
118 case ADDED_NID3:
119 return a->nid - b->nid;
120 default:
121 /* abort(); */
122 return 0;
123 }
124}
125
126static int init_added(void)
127{
128 if (added != NULL((void*)0))
129 return 1;
130 added = lh_ADDED_OBJ_new(added_obj_hash, added_obj_cmp);
131 return added != NULL((void*)0);
132}
133
134static void cleanup1_doall(ADDED_OBJ *a)
135{
136 a->obj->nid = 0;
137 a->obj->flags |= ASN1_OBJECT_FLAG_DYNAMIC0x01 |
138 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS0x04 | ASN1_OBJECT_FLAG_DYNAMIC_DATA0x08;
139}
140
141static void cleanup2_doall(ADDED_OBJ *a)
142{
143 a->obj->nid++;
144}
145
146static void cleanup3_doall(ADDED_OBJ *a)
147{
148 if (--a->obj->nid == 0)
149 ASN1_OBJECT_free(a->obj);
150 OPENSSL_free(a)CRYPTO_free(a, "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 150)
;
151}
152
153void ossl_obj_cleanup_int(void)
154{
155 if (added == NULL((void*)0))
156 return;
157 lh_ADDED_OBJ_set_down_load(added, 0);
158 lh_ADDED_OBJ_doall(added, cleanup1_doall); /* zero counters */
159 lh_ADDED_OBJ_doall(added, cleanup2_doall); /* set counters */
160 lh_ADDED_OBJ_doall(added, cleanup3_doall); /* free objects */
161 lh_ADDED_OBJ_free(added);
162 added = NULL((void*)0);
163}
164
165int OBJ_new_nid(int num)
166{
167 int i;
168
169 i = new_nid;
170 new_nid += num;
171 return i;
172}
173
174int OBJ_add_object(const ASN1_OBJECT *obj)
175{
176 ASN1_OBJECT *o;
177 ADDED_OBJ *ao[4] = { NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0) }, *aop;
178 int i;
179
180 if (added == NULL((void*)0))
181 if (!init_added())
182 return 0;
183 if ((o = OBJ_dup(obj)) == NULL((void*)0))
184 goto err;
185 if ((ao[ADDED_NID3] = OPENSSL_malloc(sizeof(*ao[0]))CRYPTO_malloc(sizeof(*ao[0]), "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 185)
) == NULL((void*)0))
186 goto err2;
187 if ((o->length != 0) && (obj->data != NULL((void*)0)))
188 if ((ao[ADDED_DATA0] = OPENSSL_malloc(sizeof(*ao[0]))CRYPTO_malloc(sizeof(*ao[0]), "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 188)
) == NULL((void*)0))
189 goto err2;
190 if (o->sn != NULL((void*)0))
191 if ((ao[ADDED_SNAME1] = OPENSSL_malloc(sizeof(*ao[0]))CRYPTO_malloc(sizeof(*ao[0]), "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 191)
) == NULL((void*)0))
192 goto err2;
193 if (o->ln != NULL((void*)0))
194 if ((ao[ADDED_LNAME2] = OPENSSL_malloc(sizeof(*ao[0]))CRYPTO_malloc(sizeof(*ao[0]), "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 194)
) == NULL((void*)0))
195 goto err2;
196
197 for (i = ADDED_DATA0; i <= ADDED_NID3; i++) {
198 if (ao[i] != NULL((void*)0)) {
199 ao[i]->type = i;
200 ao[i]->obj = o;
201 aop = lh_ADDED_OBJ_insert(added, ao[i]);
202 /* memory leak, but should not normally matter */
203 OPENSSL_free(aop)CRYPTO_free(aop, "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 203)
;
204 }
205 }
206 o->flags &=
207 ~(ASN1_OBJECT_FLAG_DYNAMIC0x01 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS0x04 |
208 ASN1_OBJECT_FLAG_DYNAMIC_DATA0x08);
209
210 return o->nid;
211 err2:
212 ERR_raise(ERR_LIB_OBJ, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,212,__func__), ERR_set_error)((8),((256|((0x1 << 18L)|
(0x2 << 18L)))),((void*)0))
;
213 err:
214 for (i = ADDED_DATA0; i <= ADDED_NID3; i++)
215 OPENSSL_free(ao[i])CRYPTO_free(ao[i], "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 215)
;
216 ASN1_OBJECT_free(o);
217 return NID_undef0;
218}
219
220ASN1_OBJECT *OBJ_nid2obj(int n)
221{
222 ADDED_OBJ ad, *adp;
223 ASN1_OBJECT ob;
224
225 if ((n >= 0) && (n < NUM_NID1248)) {
226 if ((n != NID_undef0) && (nid_objs[n].nid == NID_undef0)) {
227 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,227,__func__), ERR_set_error)((8),(101),((void*)0))
;
228 return NULL((void*)0);
229 }
230 return (ASN1_OBJECT *)&(nid_objs[n]);
231 }
232
233 /* Make sure we've loaded config before checking for any "added" objects */
234 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG0x00000040L, NULL((void*)0));
235
236 if (added == NULL((void*)0))
237 return NULL((void*)0);
238
239 ad.type = ADDED_NID3;
240 ad.obj = &ob;
241 ob.nid = n;
242 adp = lh_ADDED_OBJ_retrieve(added, &ad);
243 if (adp != NULL((void*)0))
244 return adp->obj;
245
246 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,246,__func__), ERR_set_error)((8),(101),((void*)0))
;
247 return NULL((void*)0);
248}
249
250const char *OBJ_nid2sn(int n)
251{
252 ADDED_OBJ ad, *adp;
253 ASN1_OBJECT ob;
254
255 if ((n >= 0) && (n < NUM_NID1248)) {
256 if ((n != NID_undef0) && (nid_objs[n].nid == NID_undef0)) {
257 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,257,__func__), ERR_set_error)((8),(101),((void*)0))
;
258 return NULL((void*)0);
259 }
260 return nid_objs[n].sn;
261 }
262
263 /* Make sure we've loaded config before checking for any "added" objects */
264 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG0x00000040L, NULL((void*)0));
265
266 if (added == NULL((void*)0))
267 return NULL((void*)0);
268
269 ad.type = ADDED_NID3;
270 ad.obj = &ob;
271 ob.nid = n;
272 adp = lh_ADDED_OBJ_retrieve(added, &ad);
273 if (adp != NULL((void*)0))
274 return adp->obj->sn;
275
276 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,276,__func__), ERR_set_error)((8),(101),((void*)0))
;
277 return NULL((void*)0);
278}
279
280const char *OBJ_nid2ln(int n)
281{
282 ADDED_OBJ ad, *adp;
283 ASN1_OBJECT ob;
284
285 if ((n >= 0) && (n < NUM_NID1248)) {
286 if ((n != NID_undef0) && (nid_objs[n].nid == NID_undef0)) {
287 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,287,__func__), ERR_set_error)((8),(101),((void*)0))
;
288 return NULL((void*)0);
289 }
290 return nid_objs[n].ln;
291 }
292
293 /* Make sure we've loaded config before checking for any "added" objects */
294 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG0x00000040L, NULL((void*)0));
295
296 if (added == NULL((void*)0))
297 return NULL((void*)0);
298
299 ad.type = ADDED_NID3;
300 ad.obj = &ob;
301 ob.nid = n;
302 adp = lh_ADDED_OBJ_retrieve(added, &ad);
303 if (adp != NULL((void*)0))
304 return adp->obj->ln;
305
306 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_NID)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,306,__func__), ERR_set_error)((8),(101),((void*)0))
;
307 return NULL((void*)0);
308}
309
310static int obj_cmp(const ASN1_OBJECT *const *ap, const unsigned int *bp)
311{
312 int j;
313 const ASN1_OBJECT *a = *ap;
314 const ASN1_OBJECT *b = &nid_objs[*bp];
315
316 j = (a->length - b->length);
317 if (j)
318 return j;
319 if (a->length == 0)
320 return 0;
321 return memcmp(a->data, b->data, a->length);
322}
323
324IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj)static int obj_cmp_BSEARCH_CMP_FN(const void *a_, const void *
b_) { const ASN1_OBJECT * const *a = a_; unsigned int const *
b = b_; return obj_cmp(a,b); } static unsigned int *OBJ_bsearch_obj
(const ASN1_OBJECT * *key, unsigned int const *base, int num)
{ return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof
(unsigned int), obj_cmp_BSEARCH_CMP_FN); } extern void dummy_prototype
(void)
;
325
326int OBJ_obj2nid(const ASN1_OBJECT *a)
327{
328 const unsigned int *op;
329 ADDED_OBJ ad, *adp;
330
331 if (a == NULL((void*)0))
332 return NID_undef0;
333 if (a->nid != 0)
334 return a->nid;
335
336 if (a->length == 0)
337 return NID_undef0;
338
339 /* Make sure we've loaded config before checking for any "added" objects */
340 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG0x00000040L, NULL((void*)0));
341
342 if (added != NULL((void*)0)) {
343 ad.type = ADDED_DATA0;
344 ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */
345 adp = lh_ADDED_OBJ_retrieve(added, &ad);
346 if (adp != NULL((void*)0))
347 return adp->obj->nid;
348 }
349 op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ1110);
350 if (op == NULL((void*)0))
351 return NID_undef0;
352 return nid_objs[*op].nid;
353}
354
355/*
356 * Convert an object name into an ASN1_OBJECT if "noname" is not set then
357 * search for short and long names first. This will convert the "dotted" form
358 * into an object: unlike OBJ_txt2nid it can be used with any objects, not
359 * just registered ones.
360 */
361
362ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
363{
364 int nid = NID_undef0;
365 ASN1_OBJECT *op;
366 unsigned char *buf;
367 unsigned char *p;
368 const unsigned char *cp;
369 int i, j;
370
371 if (!no_name) {
372 if (((nid = OBJ_sn2nid(s)) != NID_undef0) ||
373 ((nid = OBJ_ln2nid(s)) != NID_undef0))
374 return OBJ_nid2obj(nid);
375 if (!ossl_isdigit(*s)) {
376 ERR_raise(ERR_LIB_OBJ, OBJ_R_UNKNOWN_OBJECT_NAME)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,376,__func__), ERR_set_error)((8),(103),((void*)0))
;
377 return NULL((void*)0);
378 }
379 }
380
381 /* Work out size of content octets */
382 i = a2d_ASN1_OBJECT(NULL((void*)0), 0, s, -1);
383 if (i <= 0) {
384 /* Don't clear the error */
385 /*
386 * ERR_clear_error();
387 */
388 return NULL((void*)0);
389 }
390 /* Work out total size */
391 j = ASN1_object_size(0, i, V_ASN1_OBJECT6);
392 if (j < 0)
393 return NULL((void*)0);
394
395 if ((buf = OPENSSL_malloc(j)CRYPTO_malloc(j, "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 395)
) == NULL((void*)0)) {
396 ERR_raise(ERR_LIB_OBJ, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,396,__func__), ERR_set_error)((8),((256|((0x1 << 18L)|
(0x2 << 18L)))),((void*)0))
;
397 return NULL((void*)0);
398 }
399
400 p = buf;
401 /* Write out tag+length */
402 ASN1_put_object(&p, 0, i, V_ASN1_OBJECT6, V_ASN1_UNIVERSAL0x00);
403 /* Write out contents */
404 a2d_ASN1_OBJECT(p, i, s, -1);
405
406 cp = buf;
407 op = d2i_ASN1_OBJECT(NULL((void*)0), &cp, j);
408 OPENSSL_free(buf)CRYPTO_free(buf, "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 408)
;
409 return op;
410}
411
412int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
413{
414 int i, n = 0, len, nid, first, use_bn;
415 BIGNUM *bl;
416 unsigned long l;
417 const unsigned char *p;
418 char tbuf[DECIMAL_SIZE(i)((sizeof(i)*8+2)/3+1) + DECIMAL_SIZE(l)((sizeof(l)*8+2)/3+1) + 2];
419
420 /* Ensure that, at every state, |buf| is NUL-terminated. */
421 if (buf && buf_len > 0)
422 buf[0] = '\0';
423
424 if ((a == NULL((void*)0)) || (a->data == NULL((void*)0)))
425 return 0;
426
427 if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef0) {
428 const char *s;
429 s = OBJ_nid2ln(nid);
430 if (s == NULL((void*)0))
431 s = OBJ_nid2sn(nid);
432 if (s) {
433 if (buf)
434 OPENSSL_strlcpy(buf, s, buf_len);
435 n = strlen(s);
436 return n;
437 }
438 }
439
440 len = a->length;
441 p = a->data;
442
443 first = 1;
444 bl = NULL((void*)0);
445
446 while (len > 0) {
447 l = 0;
448 use_bn = 0;
449 for (;;) {
450 unsigned char c = *p++;
451 len--;
452 if ((len == 0) && (c & 0x80))
453 goto err;
454 if (use_bn) {
455 if (!BN_add_word(bl, c & 0x7f))
456 goto err;
457 } else
458 l |= c & 0x7f;
459 if (!(c & 0x80))
460 break;
461 if (!use_bn && (l > (ULONG_MAX(9223372036854775807L *2UL+1UL) >> 7L))) {
462 if (bl == NULL((void*)0) && (bl = BN_new()) == NULL((void*)0))
463 goto err;
464 if (!BN_set_word(bl, l))
465 goto err;
466 use_bn = 1;
467 }
468 if (use_bn) {
469 if (!BN_lshift(bl, bl, 7))
470 goto err;
471 } else
472 l <<= 7L;
473 }
474
475 if (first) {
476 first = 0;
477 if (l >= 80) {
478 i = 2;
479 if (use_bn) {
480 if (!BN_sub_word(bl, 80))
481 goto err;
482 } else
483 l -= 80;
484 } else {
485 i = (int)(l / 40);
486 l -= (long)(i * 40);
487 }
488 if (buf && (buf_len > 1)) {
489 *buf++ = i + '0';
490 *buf = '\0';
491 buf_len--;
492 }
493 n++;
494 }
495
496 if (use_bn) {
497 char *bndec;
498 bndec = BN_bn2dec(bl);
499 if (!bndec)
500 goto err;
501 i = strlen(bndec);
502 if (buf) {
503 if (buf_len > 1) {
504 *buf++ = '.';
505 *buf = '\0';
506 buf_len--;
507 }
508 OPENSSL_strlcpy(buf, bndec, buf_len);
509 if (i > buf_len) {
510 buf += buf_len;
511 buf_len = 0;
512 } else {
513 buf += i;
514 buf_len -= i;
515 }
516 }
517 n++;
518 n += i;
519 OPENSSL_free(bndec)CRYPTO_free(bndec, "../deps/openssl/openssl/crypto/objects/obj_dat.c"
, 519)
;
520 } else {
521 BIO_snprintf(tbuf, sizeof(tbuf), ".%lu", l);
522 i = strlen(tbuf);
523 if (buf && (buf_len > 0)) {
524 OPENSSL_strlcpy(buf, tbuf, buf_len);
525 if (i > buf_len) {
526 buf += buf_len;
527 buf_len = 0;
528 } else {
529 buf += i;
530 buf_len -= i;
531 }
532 }
533 n += i;
534 l = 0;
Value stored to 'l' is never read
535 }
536 }
537
538 BN_free(bl);
539 return n;
540
541 err:
542 BN_free(bl);
543 return -1;
544}
545
546int OBJ_txt2nid(const char *s)
547{
548 ASN1_OBJECT *obj;
549 int nid;
550 obj = OBJ_txt2obj(s, 0);
551 nid = OBJ_obj2nid(obj);
552 ASN1_OBJECT_free(obj);
553 return nid;
554}
555
556int OBJ_ln2nid(const char *s)
557{
558 ASN1_OBJECT o;
559 const ASN1_OBJECT *oo = &o;
560 ADDED_OBJ ad, *adp;
561 const unsigned int *op;
562
563 /* Make sure we've loaded config before checking for any "added" objects */
564 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG0x00000040L, NULL((void*)0));
565
566 o.ln = s;
567 if (added != NULL((void*)0)) {
568 ad.type = ADDED_LNAME2;
569 ad.obj = &o;
570 adp = lh_ADDED_OBJ_retrieve(added, &ad);
571 if (adp != NULL((void*)0))
572 return adp->obj->nid;
573 }
574 op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN1239);
575 if (op == NULL((void*)0))
576 return NID_undef0;
577 return nid_objs[*op].nid;
578}
579
580int OBJ_sn2nid(const char *s)
581{
582 ASN1_OBJECT o;
583 const ASN1_OBJECT *oo = &o;
584 ADDED_OBJ ad, *adp;
585 const unsigned int *op;
586
587 /* Make sure we've loaded config before checking for any "added" objects */
588 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG0x00000040L, NULL((void*)0));
589
590 o.sn = s;
591 if (added != NULL((void*)0)) {
592 ad.type = ADDED_SNAME1;
593 ad.obj = &o;
594 adp = lh_ADDED_OBJ_retrieve(added, &ad);
595 if (adp != NULL((void*)0))
596 return adp->obj->nid;
597 }
598 op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN1239);
599 if (op == NULL((void*)0))
600 return NID_undef0;
601 return nid_objs[*op].nid;
602}
603
604const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
605 int (*cmp) (const void *, const void *))
606{
607 return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
608}
609
610const void *OBJ_bsearch_ex_(const void *key, const void *base, int num,
611 int size,
612 int (*cmp) (const void *, const void *),
613 int flags)
614{
615 const char *p = ossl_bsearch(key, base, num, size, cmp, flags);
616
617#ifdef CHARSET_EBCDIC
618 /*
619 * THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and I
620 * don't have perl (yet), we revert to a *LINEAR* search when the object
621 * wasn't found in the binary search.
622 */
623 if (p == NULL((void*)0)) {
624 const char *base_ = base;
625 int l, h, i = 0, c = 0;
626
627 for (i = 0; i < num; ++i) {
628 p = &(base_[i * size]);
629 c = (*cmp) (key, p);
630 if (c == 0
631 || (c < 0 && (flags & OBJ_BSEARCH_VALUE_ON_NOMATCH0x01)))
632 return p;
633 }
634 }
635#endif
636 return p;
637}
638
639/*
640 * Parse a BIO sink to create some extra oid's objects.
641 * Line format:<OID:isdigit or '.']><isspace><SN><isspace><LN>
642 */
643int OBJ_create_objects(BIO *in)
644{
645 char buf[512];
646 int i, num = 0;
647 char *o, *s, *l = NULL((void*)0);
648
649 for (;;) {
650 s = o = NULL((void*)0);
651 i = BIO_gets(in, buf, 512);
652 if (i <= 0)
653 return num;
654 buf[i - 1] = '\0';
655 if (!ossl_isalnum(buf[0])(ossl_ctype_check((buf[0]), ((0x1 | 0x2) | 0x4))))
656 return num;
657 o = s = buf;
658 while (ossl_isdigit(*s) || *s == '.')
659 s++;
660 if (*s != '\0') {
661 *(s++) = '\0';
662 while (ossl_isspace(*s)(ossl_ctype_check((*s), 0x8)))
663 s++;
664 if (*s == '\0') {
665 s = NULL((void*)0);
666 } else {
667 l = s;
668 while (*l != '\0' && !ossl_isspace(*l)(ossl_ctype_check((*l), 0x8)))
669 l++;
670 if (*l != '\0') {
671 *(l++) = '\0';
672 while (ossl_isspace(*l)(ossl_ctype_check((*l), 0x8)))
673 l++;
674 if (*l == '\0') {
675 l = NULL((void*)0);
676 }
677 } else {
678 l = NULL((void*)0);
679 }
680 }
681 } else {
682 s = NULL((void*)0);
683 }
684 if (*o == '\0')
685 return num;
686 if (!OBJ_create(o, s, l))
687 return num;
688 num++;
689 }
690}
691
692int OBJ_create(const char *oid, const char *sn, const char *ln)
693{
694 ASN1_OBJECT *tmpoid = NULL((void*)0);
695 int ok = 0;
696
697 /* Check to see if short or long name already present */
698 if ((sn != NULL((void*)0) && OBJ_sn2nid(sn) != NID_undef0)
699 || (ln != NULL((void*)0) && OBJ_ln2nid(ln) != NID_undef0)) {
700 ERR_raise(ERR_LIB_OBJ, OBJ_R_OID_EXISTS)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,700,__func__), ERR_set_error)((8),(102),((void*)0))
;
701 return 0;
702 }
703
704 /* Convert numerical OID string to an ASN1_OBJECT structure */
705 tmpoid = OBJ_txt2obj(oid, 1);
706 if (tmpoid == NULL((void*)0))
707 return 0;
708
709 /* If NID is not NID_undef then object already exists */
710 if (OBJ_obj2nid(tmpoid) != NID_undef0) {
711 ERR_raise(ERR_LIB_OBJ, OBJ_R_OID_EXISTS)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/objects/obj_dat.c"
,711,__func__), ERR_set_error)((8),(102),((void*)0))
;
712 goto err;
713 }
714
715 tmpoid->nid = OBJ_new_nid(1);
716 tmpoid->sn = (char *)sn;
717 tmpoid->ln = (char *)ln;
718
719 ok = OBJ_add_object(tmpoid);
720
721 tmpoid->sn = NULL((void*)0);
722 tmpoid->ln = NULL((void*)0);
723
724 err:
725 ASN1_OBJECT_free(tmpoid);
726 return ok;
727}
728
729size_t OBJ_length(const ASN1_OBJECT *obj)
730{
731 if (obj == NULL((void*)0))
732 return 0;
733 return obj->length;
734}
735
736const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj)
737{
738 if (obj == NULL((void*)0))
739 return NULL((void*)0);
740 return obj->data;
741}