Bug Summary

File:out/../deps/openssl/openssl/crypto/param_build.c
Warning:line 337, column 17
Null pointer passed to 1st parameter expecting 'nonnull'

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 param_build.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/param_build.c
1/*
2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
11#include <string.h>
12#include <openssl/err.h>
13#include <openssl/cryptoerr.h>
14#include <openssl/params.h>
15#include <openssl/types.h>
16#include <openssl/safestack.h>
17#include "internal/param_build_set.h"
18
19/*
20 * Special internal param type to indicate the end of an allocate OSSL_PARAM
21 * array.
22 */
23
24typedef struct {
25 const char *key;
26 int type;
27 int secure;
28 size_t size;
29 size_t alloc_blocks;
30 const BIGNUM *bn;
31 const void *string;
32 union {
33 /*
34 * These fields are never directly addressed, but their sizes are
35 * imporant so that all native types can be copied here without overrun.
36 */
37 ossl_intmax_t i;
38 ossl_uintmax_t u;
39 double d;
40 } num;
41} OSSL_PARAM_BLD_DEF;
42
43DEFINE_STACK_OF(OSSL_PARAM_BLD_DEF)struct stack_st_OSSL_PARAM_BLD_DEF; typedef int (*sk_OSSL_PARAM_BLD_DEF_compfunc
)(const OSSL_PARAM_BLD_DEF * const *a, const OSSL_PARAM_BLD_DEF
*const *b); typedef void (*sk_OSSL_PARAM_BLD_DEF_freefunc)(OSSL_PARAM_BLD_DEF
*a); typedef OSSL_PARAM_BLD_DEF * (*sk_OSSL_PARAM_BLD_DEF_copyfunc
)(const OSSL_PARAM_BLD_DEF *a); static __attribute__((unused)
) inline int sk_OSSL_PARAM_BLD_DEF_num(const struct stack_st_OSSL_PARAM_BLD_DEF
*sk) { return OPENSSL_sk_num((const OPENSSL_STACK *)sk); } static
__attribute__((unused)) inline OSSL_PARAM_BLD_DEF *sk_OSSL_PARAM_BLD_DEF_value
(const struct stack_st_OSSL_PARAM_BLD_DEF *sk, int idx) { return
(OSSL_PARAM_BLD_DEF *)OPENSSL_sk_value((const OPENSSL_STACK *
)sk, idx); } static __attribute__((unused)) inline struct stack_st_OSSL_PARAM_BLD_DEF
*sk_OSSL_PARAM_BLD_DEF_new(sk_OSSL_PARAM_BLD_DEF_compfunc compare
) { return (struct stack_st_OSSL_PARAM_BLD_DEF *)OPENSSL_sk_new
((OPENSSL_sk_compfunc)compare); } static __attribute__((unused
)) inline struct stack_st_OSSL_PARAM_BLD_DEF *sk_OSSL_PARAM_BLD_DEF_new_null
(void) { return (struct stack_st_OSSL_PARAM_BLD_DEF *)OPENSSL_sk_new_null
(); } static __attribute__((unused)) inline struct stack_st_OSSL_PARAM_BLD_DEF
*sk_OSSL_PARAM_BLD_DEF_new_reserve(sk_OSSL_PARAM_BLD_DEF_compfunc
compare, int n) { return (struct stack_st_OSSL_PARAM_BLD_DEF
*)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); }
static __attribute__((unused)) inline int sk_OSSL_PARAM_BLD_DEF_reserve
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, int n) { return OPENSSL_sk_reserve
((OPENSSL_STACK *)sk, n); } static __attribute__((unused)) inline
void sk_OSSL_PARAM_BLD_DEF_free(struct stack_st_OSSL_PARAM_BLD_DEF
*sk) { OPENSSL_sk_free((OPENSSL_STACK *)sk); } static __attribute__
((unused)) inline void sk_OSSL_PARAM_BLD_DEF_zero(struct stack_st_OSSL_PARAM_BLD_DEF
*sk) { OPENSSL_sk_zero((OPENSSL_STACK *)sk); } static __attribute__
((unused)) inline OSSL_PARAM_BLD_DEF *sk_OSSL_PARAM_BLD_DEF_delete
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, int i) { return (OSSL_PARAM_BLD_DEF
*)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); } static __attribute__
((unused)) inline OSSL_PARAM_BLD_DEF *sk_OSSL_PARAM_BLD_DEF_delete_ptr
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, OSSL_PARAM_BLD_DEF *
ptr) { return (OSSL_PARAM_BLD_DEF *)OPENSSL_sk_delete_ptr((OPENSSL_STACK
*)sk, (const void *)ptr); } static __attribute__((unused)) inline
int sk_OSSL_PARAM_BLD_DEF_push(struct stack_st_OSSL_PARAM_BLD_DEF
*sk, OSSL_PARAM_BLD_DEF *ptr) { return OPENSSL_sk_push((OPENSSL_STACK
*)sk, (const void *)ptr); } static __attribute__((unused)) inline
int sk_OSSL_PARAM_BLD_DEF_unshift(struct stack_st_OSSL_PARAM_BLD_DEF
*sk, OSSL_PARAM_BLD_DEF *ptr) { return OPENSSL_sk_unshift((OPENSSL_STACK
*)sk, (const void *)ptr); } static __attribute__((unused)) inline
OSSL_PARAM_BLD_DEF *sk_OSSL_PARAM_BLD_DEF_pop(struct stack_st_OSSL_PARAM_BLD_DEF
*sk) { return (OSSL_PARAM_BLD_DEF *)OPENSSL_sk_pop((OPENSSL_STACK
*)sk); } static __attribute__((unused)) inline OSSL_PARAM_BLD_DEF
*sk_OSSL_PARAM_BLD_DEF_shift(struct stack_st_OSSL_PARAM_BLD_DEF
*sk) { return (OSSL_PARAM_BLD_DEF *)OPENSSL_sk_shift((OPENSSL_STACK
*)sk); } static __attribute__((unused)) inline void sk_OSSL_PARAM_BLD_DEF_pop_free
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, sk_OSSL_PARAM_BLD_DEF_freefunc
freefunc) { OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc
)freefunc); } static __attribute__((unused)) inline int sk_OSSL_PARAM_BLD_DEF_insert
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, OSSL_PARAM_BLD_DEF *
ptr, int idx) { return OPENSSL_sk_insert((OPENSSL_STACK *)sk,
(const void *)ptr, idx); } static __attribute__((unused)) inline
OSSL_PARAM_BLD_DEF *sk_OSSL_PARAM_BLD_DEF_set(struct stack_st_OSSL_PARAM_BLD_DEF
*sk, int idx, OSSL_PARAM_BLD_DEF *ptr) { return (OSSL_PARAM_BLD_DEF
*)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr
); } static __attribute__((unused)) inline int sk_OSSL_PARAM_BLD_DEF_find
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, OSSL_PARAM_BLD_DEF *
ptr) { return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void
*)ptr); } static __attribute__((unused)) inline int sk_OSSL_PARAM_BLD_DEF_find_ex
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, OSSL_PARAM_BLD_DEF *
ptr) { return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void
*)ptr); } static __attribute__((unused)) inline int sk_OSSL_PARAM_BLD_DEF_find_all
(struct stack_st_OSSL_PARAM_BLD_DEF *sk, OSSL_PARAM_BLD_DEF *
ptr, int *pnum) { return OPENSSL_sk_find_all((OPENSSL_STACK *
)sk, (const void *)ptr, pnum); } static __attribute__((unused
)) inline void sk_OSSL_PARAM_BLD_DEF_sort(struct stack_st_OSSL_PARAM_BLD_DEF
*sk) { OPENSSL_sk_sort((OPENSSL_STACK *)sk); } static __attribute__
((unused)) inline int sk_OSSL_PARAM_BLD_DEF_is_sorted(const struct
stack_st_OSSL_PARAM_BLD_DEF *sk) { return OPENSSL_sk_is_sorted
((const OPENSSL_STACK *)sk); } static __attribute__((unused))
inline struct stack_st_OSSL_PARAM_BLD_DEF * sk_OSSL_PARAM_BLD_DEF_dup
(const struct stack_st_OSSL_PARAM_BLD_DEF *sk) { return (struct
stack_st_OSSL_PARAM_BLD_DEF *)OPENSSL_sk_dup((const OPENSSL_STACK
*)sk); } static __attribute__((unused)) inline struct stack_st_OSSL_PARAM_BLD_DEF
*sk_OSSL_PARAM_BLD_DEF_deep_copy(const struct stack_st_OSSL_PARAM_BLD_DEF
*sk, sk_OSSL_PARAM_BLD_DEF_copyfunc copyfunc, sk_OSSL_PARAM_BLD_DEF_freefunc
freefunc) { return (struct stack_st_OSSL_PARAM_BLD_DEF *)OPENSSL_sk_deep_copy
((const OPENSSL_STACK *)sk, (OPENSSL_sk_copyfunc)copyfunc, (OPENSSL_sk_freefunc
)freefunc); } static __attribute__((unused)) inline sk_OSSL_PARAM_BLD_DEF_compfunc
sk_OSSL_PARAM_BLD_DEF_set_cmp_func(struct stack_st_OSSL_PARAM_BLD_DEF
*sk, sk_OSSL_PARAM_BLD_DEF_compfunc compare) { return (sk_OSSL_PARAM_BLD_DEF_compfunc
)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc
)compare); }
44
45struct ossl_param_bld_st {
46 size_t total_blocks;
47 size_t secure_blocks;
48 STACK_OF(OSSL_PARAM_BLD_DEF)struct stack_st_OSSL_PARAM_BLD_DEF *params;
49};
50
51static OSSL_PARAM_BLD_DEF *param_push(OSSL_PARAM_BLD *bld, const char *key,
52 int size, size_t alloc, int type,
53 int secure)
54{
55 OSSL_PARAM_BLD_DEF *pd = OPENSSL_zalloc(sizeof(*pd))CRYPTO_zalloc(sizeof(*pd), "../deps/openssl/openssl/crypto/param_build.c"
, 55)
;
56
57 if (pd == NULL((void*)0)) {
58 ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,58,__func__), ERR_set_error)((15),((256|((0x1 << 18L)|
(0x2 << 18L)))),((void*)0))
;
59 return NULL((void*)0);
60 }
61 pd->key = key;
62 pd->type = type;
63 pd->size = size;
64 pd->alloc_blocks = ossl_param_bytes_to_blocks(alloc);
65 if ((pd->secure = secure) != 0)
66 bld->secure_blocks += pd->alloc_blocks;
67 else
68 bld->total_blocks += pd->alloc_blocks;
69 if (sk_OSSL_PARAM_BLD_DEF_push(bld->params, pd) <= 0) {
70 OPENSSL_free(pd)CRYPTO_free(pd, "../deps/openssl/openssl/crypto/param_build.c"
, 70)
;
71 pd = NULL((void*)0);
72 }
73 return pd;
74}
75
76static int param_push_num(OSSL_PARAM_BLD *bld, const char *key,
77 void *num, size_t size, int type)
78{
79 OSSL_PARAM_BLD_DEF *pd = param_push(bld, key, size, size, type, 0);
80
81 if (pd == NULL((void*)0))
82 return 0;
83 if (size > sizeof(pd->num)) {
84 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_TOO_MANY_BYTES)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,84,__func__), ERR_set_error)((15),(113),((void*)0))
;
85 return 0;
86 }
87 memcpy(&pd->num, num, size);
88 return 1;
89}
90
91OSSL_PARAM_BLD *OSSL_PARAM_BLD_new(void)
92{
93 OSSL_PARAM_BLD *r = OPENSSL_zalloc(sizeof(OSSL_PARAM_BLD))CRYPTO_zalloc(sizeof(OSSL_PARAM_BLD), "../deps/openssl/openssl/crypto/param_build.c"
, 93)
;
94
95 if (r != NULL((void*)0)) {
96 r->params = sk_OSSL_PARAM_BLD_DEF_new_null();
97 if (r->params == NULL((void*)0)) {
98 OPENSSL_free(r)CRYPTO_free(r, "../deps/openssl/openssl/crypto/param_build.c"
, 98)
;
99 r = NULL((void*)0);
100 }
101 }
102 return r;
103}
104
105static void free_all_params(OSSL_PARAM_BLD *bld)
106{
107 int i, n = sk_OSSL_PARAM_BLD_DEF_num(bld->params);
108
109 for (i = 0; i < n; i++)
110 OPENSSL_free(sk_OSSL_PARAM_BLD_DEF_pop(bld->params))CRYPTO_free(sk_OSSL_PARAM_BLD_DEF_pop(bld->params), "../deps/openssl/openssl/crypto/param_build.c"
, 110)
;
111}
112
113void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld)
114{
115 if (bld == NULL((void*)0))
116 return;
117 free_all_params(bld);
118 sk_OSSL_PARAM_BLD_DEF_free(bld->params);
119 OPENSSL_free(bld)CRYPTO_free(bld, "../deps/openssl/openssl/crypto/param_build.c"
, 119)
;
120}
121
122int OSSL_PARAM_BLD_push_int(OSSL_PARAM_BLD *bld, const char *key, int num)
123{
124 return param_push_num(bld, key, &num, sizeof(num), OSSL_PARAM_INTEGER1);
125}
126
127int OSSL_PARAM_BLD_push_uint(OSSL_PARAM_BLD *bld, const char *key,
128 unsigned int num)
129{
130 return param_push_num(bld, key, &num, sizeof(num),
131 OSSL_PARAM_UNSIGNED_INTEGER2);
132}
133
134int OSSL_PARAM_BLD_push_long(OSSL_PARAM_BLD *bld, const char *key,
135 long int num)
136{
137 return param_push_num(bld, key, &num, sizeof(num), OSSL_PARAM_INTEGER1);
138}
139
140int OSSL_PARAM_BLD_push_ulong(OSSL_PARAM_BLD *bld, const char *key,
141 unsigned long int num)
142{
143 return param_push_num(bld, key, &num, sizeof(num),
144 OSSL_PARAM_UNSIGNED_INTEGER2);
145}
146
147int OSSL_PARAM_BLD_push_int32(OSSL_PARAM_BLD *bld, const char *key,
148 int32_t num)
149{
150 return param_push_num(bld, key, &num, sizeof(num), OSSL_PARAM_INTEGER1);
151}
152
153int OSSL_PARAM_BLD_push_uint32(OSSL_PARAM_BLD *bld, const char *key,
154 uint32_t num)
155{
156 return param_push_num(bld, key, &num, sizeof(num),
157 OSSL_PARAM_UNSIGNED_INTEGER2);
158}
159
160int OSSL_PARAM_BLD_push_int64(OSSL_PARAM_BLD *bld, const char *key,
161 int64_t num)
162{
163 return param_push_num(bld, key, &num, sizeof(num), OSSL_PARAM_INTEGER1);
164}
165
166int OSSL_PARAM_BLD_push_uint64(OSSL_PARAM_BLD *bld, const char *key,
167 uint64_t num)
168{
169 return param_push_num(bld, key, &num, sizeof(num),
170 OSSL_PARAM_UNSIGNED_INTEGER2);
171}
172
173int OSSL_PARAM_BLD_push_size_t(OSSL_PARAM_BLD *bld, const char *key,
174 size_t num)
175{
176 return param_push_num(bld, key, &num, sizeof(num),
177 OSSL_PARAM_UNSIGNED_INTEGER2);
178}
179
180int OSSL_PARAM_BLD_push_time_t(OSSL_PARAM_BLD *bld, const char *key,
181 time_t num)
182{
183 return param_push_num(bld, key, &num, sizeof(num),
184 OSSL_PARAM_INTEGER1);
185}
186
187int OSSL_PARAM_BLD_push_double(OSSL_PARAM_BLD *bld, const char *key,
188 double num)
189{
190 return param_push_num(bld, key, &num, sizeof(num), OSSL_PARAM_REAL3);
191}
192
193int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
194 const BIGNUM *bn)
195{
196 return OSSL_PARAM_BLD_push_BN_pad(bld, key, bn,
197 bn == NULL((void*)0) ? 0 : BN_num_bytes(bn)((BN_num_bits(bn)+7)/8));
198}
199
200int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
201 const BIGNUM *bn, size_t sz)
202{
203 int n, secure = 0;
204 OSSL_PARAM_BLD_DEF *pd;
205
206 if (bn != NULL((void*)0)) {
207 if (BN_is_negative(bn)) {
208 ERR_raise_data(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,208,__func__), ERR_set_error)
(ERR_LIB_CRYPTO15, ERR_R_UNSUPPORTED(268|(0x2 << 18L)),
209 "Negative big numbers are unsupported for OSSL_PARAM");
210 return 0;
211 }
212
213 n = BN_num_bytes(bn)((BN_num_bits(bn)+7)/8);
214 if (n < 0) {
215 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_ZERO_LENGTH_NUMBER)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,215,__func__), ERR_set_error)((15),(115),((void*)0))
;
216 return 0;
217 }
218 if (sz < (size_t)n) {
219 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_TOO_SMALL_BUFFER)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,219,__func__), ERR_set_error)((15),(116),((void*)0))
;
220 return 0;
221 }
222 if (BN_get_flags(bn, BN_FLG_SECURE0x08) == BN_FLG_SECURE0x08)
223 secure = 1;
224 }
225 pd = param_push(bld, key, sz, sz, OSSL_PARAM_UNSIGNED_INTEGER2, secure);
226 if (pd == NULL((void*)0))
227 return 0;
228 pd->bn = bn;
229 return 1;
230}
231
232int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
233 const char *buf, size_t bsize)
234{
235 OSSL_PARAM_BLD_DEF *pd;
236 int secure;
237
238 if (bsize == 0) {
239 bsize = strlen(buf);
240 } else if (bsize > INT_MAX2147483647) {
241 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_STRING_TOO_LONG)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,241,__func__), ERR_set_error)((15),(112),((void*)0))
;
242 return 0;
243 }
244 secure = CRYPTO_secure_allocated(buf);
245 pd = param_push(bld, key, bsize, bsize + 1, OSSL_PARAM_UTF8_STRING4, secure);
246 if (pd == NULL((void*)0))
247 return 0;
248 pd->string = buf;
249 return 1;
250}
251
252int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
253 char *buf, size_t bsize)
254{
255 OSSL_PARAM_BLD_DEF *pd;
256
257 if (bsize == 0) {
258 bsize = strlen(buf);
259 } else if (bsize > INT_MAX2147483647) {
260 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_STRING_TOO_LONG)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,260,__func__), ERR_set_error)((15),(112),((void*)0))
;
261 return 0;
262 }
263 pd = param_push(bld, key, bsize, sizeof(buf), OSSL_PARAM_UTF8_PTR6, 0);
264 if (pd == NULL((void*)0))
265 return 0;
266 pd->string = buf;
267 return 1;
268}
269
270int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
271 const void *buf, size_t bsize)
272{
273 OSSL_PARAM_BLD_DEF *pd;
274 int secure;
275
276 if (bsize > INT_MAX2147483647) {
277 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_STRING_TOO_LONG)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,277,__func__), ERR_set_error)((15),(112),((void*)0))
;
278 return 0;
279 }
280 secure = CRYPTO_secure_allocated(buf);
281 pd = param_push(bld, key, bsize, bsize, OSSL_PARAM_OCTET_STRING5, secure);
282 if (pd == NULL((void*)0))
283 return 0;
284 pd->string = buf;
285 return 1;
286}
287
288int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
289 void *buf, size_t bsize)
290{
291 OSSL_PARAM_BLD_DEF *pd;
292
293 if (bsize > INT_MAX2147483647) {
294 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_STRING_TOO_LONG)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,294,__func__), ERR_set_error)((15),(112),((void*)0))
;
295 return 0;
296 }
297 pd = param_push(bld, key, bsize, sizeof(buf), OSSL_PARAM_OCTET_PTR7, 0);
298 if (pd == NULL((void*)0))
299 return 0;
300 pd->string = buf;
301 return 1;
302}
303
304static OSSL_PARAM *param_bld_convert(OSSL_PARAM_BLD *bld, OSSL_PARAM *param,
305 OSSL_PARAM_ALIGNED_BLOCK *blk,
306 OSSL_PARAM_ALIGNED_BLOCK *secure)
307{
308 int i, num = sk_OSSL_PARAM_BLD_DEF_num(bld->params);
309 OSSL_PARAM_BLD_DEF *pd;
310 void *p;
311
312 for (i = 0; i < num; i++) {
8
Assuming 'i' is < 'num'
9
Loop condition is true. Entering loop body
313 pd = sk_OSSL_PARAM_BLD_DEF_value(bld->params, i);
314 param[i].key = pd->key;
315 param[i].data_type = pd->type;
316 param[i].data_size = pd->size;
317 param[i].return_size = OSSL_PARAM_UNMODIFIED((size_t)-1);
318
319 if (pd->secure) {
10
Assuming field 'secure' is not equal to 0
11
Taking true branch
320 p = secure;
12
Null pointer value stored to 'p'
321 secure += pd->alloc_blocks;
322 } else {
323 p = blk;
324 blk += pd->alloc_blocks;
325 }
326 param[i].data = p;
327 if (pd->bn != NULL((void*)0)) {
13
Assuming field 'bn' is equal to NULL
328 /* BIGNUM */
329 BN_bn2nativepad(pd->bn, (unsigned char *)p, pd->size);
330 } else if (pd->type == OSSL_PARAM_OCTET_PTR7
14
Assuming field 'type' is not equal to OSSL_PARAM_OCTET_PTR
331 || pd->type == OSSL_PARAM_UTF8_PTR6) {
15
Assuming field 'type' is not equal to OSSL_PARAM_UTF8_PTR
332 /* PTR */
333 *(const void **)p = pd->string;
334 } else if (pd->type == OSSL_PARAM_OCTET_STRING5
16
Assuming field 'type' is equal to OSSL_PARAM_OCTET_STRING
335 || pd->type == OSSL_PARAM_UTF8_STRING4) {
336 if (pd->string != NULL((void*)0))
17
Assuming field 'string' is not equal to NULL
18
Taking true branch
337 memcpy(p, pd->string, pd->size);
19
Null pointer passed to 1st parameter expecting 'nonnull'
338 else
339 memset(p, 0, pd->size);
340 if (pd->type == OSSL_PARAM_UTF8_STRING4)
341 ((char *)p)[pd->size] = '\0';
342 } else {
343 /* Number, but could also be a NULL BIGNUM */
344 if (pd->size > sizeof(pd->num))
345 memset(p, 0, pd->size);
346 else if (pd->size > 0)
347 memcpy(p, &pd->num, pd->size);
348 }
349 }
350 param[i] = OSSL_PARAM_construct_end();
351 return param + i;
352}
353
354OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld)
355{
356 OSSL_PARAM_ALIGNED_BLOCK *blk, *s = NULL((void*)0);
1
's' initialized to a null pointer value
357 OSSL_PARAM *params, *last;
358 const int num = sk_OSSL_PARAM_BLD_DEF_num(bld->params);
359 const size_t p_blks = ossl_param_bytes_to_blocks((1 + num) * sizeof(*params));
360 const size_t total = OSSL_PARAM_ALIGN_SIZEsizeof(OSSL_PARAM_ALIGNED_BLOCK) * (p_blks + bld->total_blocks);
361 const size_t ss = OSSL_PARAM_ALIGN_SIZEsizeof(OSSL_PARAM_ALIGNED_BLOCK) * bld->secure_blocks;
362
363 if (ss > 0) {
2
Assuming 'ss' is <= 0
3
Taking false branch
364 s = OPENSSL_secure_malloc(ss)CRYPTO_secure_malloc(ss, "../deps/openssl/openssl/crypto/param_build.c"
, 364)
;
365 if (s == NULL((void*)0)) {
366 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_SECURE_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,366,__func__), ERR_set_error)((15),(111),((void*)0))
;
367 return NULL((void*)0);
368 }
369 }
370 params = OPENSSL_malloc(total)CRYPTO_malloc(total, "../deps/openssl/openssl/crypto/param_build.c"
, 370)
;
371 if (params == NULL((void*)0)) {
4
Assuming 'params' is not equal to NULL
5
Taking false branch
372 ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/param_build.c"
,372,__func__), ERR_set_error)((15),((256|((0x1 << 18L)
|(0x2 << 18L)))),((void*)0))
;
373 OPENSSL_secure_free(s)CRYPTO_secure_free(s, "../deps/openssl/openssl/crypto/param_build.c"
, 373)
;
374 return NULL((void*)0);
375 }
376 blk = p_blks + (OSSL_PARAM_ALIGNED_BLOCK *)(params);
377 last = param_bld_convert(bld, params, blk, s);
6
Passing null pointer value via 4th parameter 'secure'
7
Calling 'param_bld_convert'
378 ossl_param_set_secure_block(last, s, ss);
379
380 /* Reset builder for reuse */
381 bld->total_blocks = 0;
382 bld->secure_blocks = 0;
383 free_all_params(bld);
384 return params;
385}