Bug Summary

File:out/../deps/openssl/openssl/crypto/asn1/a_verify.c
Warning:line 73, column 5
Value stored to 'ret' 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 a_verify.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/asn1/a_verify.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 <time.h>
12#include <sys/types.h>
13
14#include "internal/cryptlib.h"
15
16#include <openssl/bn.h>
17#include <openssl/x509.h>
18#include <openssl/objects.h>
19#include <openssl/buffer.h>
20#include <openssl/evp.h>
21#include "crypto/asn1.h"
22#include "crypto/evp.h"
23#include "crypto/rsa.h"
24
25#ifndef OPENSSL_NO_DEPRECATED_3_0
26
27int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
28 char *data, EVP_PKEY *pkey)
29{
30 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
31 const EVP_MD *type;
32 unsigned char *p, *buf_in = NULL((void*)0);
33 int ret = -1, i, inl;
34
35 if (ctx == NULL((void*)0)) {
36 ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,36,__func__), ERR_set_error)((13),((256|((0x1 << 18L)|
(0x2 << 18L)))),((void*)0))
;
37 goto err;
38 }
39 i = OBJ_obj2nid(a->algorithm);
40 type = EVP_get_digestbyname(OBJ_nid2sn(i));
41 if (type == NULL((void*)0)) {
42 ERR_raise(ERR_LIB_ASN1, ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,42,__func__), ERR_set_error)((13),(161),((void*)0))
;
43 goto err;
44 }
45
46 if (signature->type == V_ASN1_BIT_STRING3 && signature->flags & 0x7) {
47 ERR_raise(ERR_LIB_ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,47,__func__), ERR_set_error)((13),(220),((void*)0))
;
48 goto err;
49 }
50
51 inl = i2d(data, NULL((void*)0));
52 if (inl <= 0) {
53 ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,53,__func__), ERR_set_error)((13),((259|((0x1 << 18L)|
(0x2 << 18L)))),((void*)0))
;
54 goto err;
55 }
56 buf_in = OPENSSL_malloc((unsigned int)inl)CRYPTO_malloc((unsigned int)inl, "../deps/openssl/openssl/crypto/asn1/a_verify.c"
, 56)
;
57 if (buf_in == NULL((void*)0)) {
58 ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,58,__func__), ERR_set_error)((13),((256|((0x1 << 18L)|
(0x2 << 18L)))),((void*)0))
;
59 goto err;
60 }
61 p = buf_in;
62
63 i2d(data, &p);
64 ret = EVP_VerifyInit_ex(ctx, type, NULL)EVP_DigestInit_ex(ctx,type,((void*)0))
65 && EVP_VerifyUpdate(ctx, (unsigned char *)buf_in, inl)EVP_DigestUpdate(ctx,(unsigned char *)buf_in,inl);
66
67 OPENSSL_clear_free(buf_in, (unsigned int)inl)CRYPTO_clear_free(buf_in, (unsigned int)inl, "../deps/openssl/openssl/crypto/asn1/a_verify.c"
, 67)
;
68
69 if (!ret) {
70 ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,70,__func__), ERR_set_error)((13),((6 | (0x2 << 18L)))
,((void*)0))
;
71 goto err;
72 }
73 ret = -1;
Value stored to 'ret' is never read
74
75 if (EVP_VerifyFinal(ctx, (unsigned char *)signature->data,
76 (unsigned int)signature->length, pkey) <= 0) {
77 ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,77,__func__), ERR_set_error)((13),((6 | (0x2 << 18L)))
,((void*)0))
;
78 ret = 0;
79 goto err;
80 }
81 ret = 1;
82 err:
83 EVP_MD_CTX_free(ctx);
84 return ret;
85}
86
87#endif
88
89int ASN1_item_verify(const ASN1_ITEM *it, const X509_ALGOR *alg,
90 const ASN1_BIT_STRING *signature, const void *data,
91 EVP_PKEY *pkey)
92{
93 return ASN1_item_verify_ex(it, alg, signature, data, NULL((void*)0), pkey, NULL((void*)0), NULL((void*)0));
94}
95
96int ASN1_item_verify_ex(const ASN1_ITEM *it, const X509_ALGOR *alg,
97 const ASN1_BIT_STRING *signature, const void *data,
98 const ASN1_OCTET_STRING *id, EVP_PKEY *pkey,
99 OSSL_LIB_CTX *libctx, const char *propq)
100{
101 EVP_MD_CTX *ctx;
102 int rv = -1;
103
104 if ((ctx = evp_md_ctx_new_ex(pkey, id, libctx, propq)) != NULL((void*)0)) {
105 rv = ASN1_item_verify_ctx(it, alg, signature, data, ctx);
106 EVP_PKEY_CTX_free(EVP_MD_CTX_get_pkey_ctx(ctx));
107 EVP_MD_CTX_free(ctx);
108 }
109 return rv;
110}
111
112int ASN1_item_verify_ctx(const ASN1_ITEM *it, const X509_ALGOR *alg,
113 const ASN1_BIT_STRING *signature, const void *data,
114 EVP_MD_CTX *ctx)
115{
116 EVP_PKEY *pkey;
117 unsigned char *buf_in = NULL((void*)0);
118 int ret = -1, inl = 0;
119 int mdnid, pknid;
120 size_t inll = 0;
121
122 pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_get_pkey_ctx(ctx));
123
124 if (pkey == NULL((void*)0)) {
125 ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_NULL_PARAMETER)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,125,__func__), ERR_set_error)((13),((258|((0x1 << 18L)
|(0x2 << 18L)))),((void*)0))
;
126 return -1;
127 }
128
129 if (signature->type == V_ASN1_BIT_STRING3 && signature->flags & 0x7) {
130 ERR_raise(ERR_LIB_ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,130,__func__), ERR_set_error)((13),(220),((void*)0))
;
131 return -1;
132 }
133
134 /* Convert signature OID into digest and public key OIDs */
135 if (!OBJ_find_sigid_algs(OBJ_obj2nid(alg->algorithm), &mdnid, &pknid)) {
136 ERR_raise(ERR_LIB_ASN1, ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,136,__func__), ERR_set_error)((13),(199),((void*)0))
;
137 goto err;
138 }
139
140 if (mdnid == NID_undef0 && evp_pkey_is_legacy(pkey)((pkey)->type != 0 && (pkey)->keymgmt == ((void
*)0))
) {
141 if (pkey->ameth == NULL((void*)0) || pkey->ameth->item_verify == NULL((void*)0)) {
142 ERR_raise(ERR_LIB_ASN1, ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,142,__func__), ERR_set_error)((13),(199),((void*)0))
;
143 goto err;
144 }
145 ret = pkey->ameth->item_verify(ctx, it, data, alg, signature, pkey);
146 /*
147 * Return values meaning:
148 * <=0: error.
149 * 1: method does everything.
150 * 2: carry on as normal, method has called EVP_DigestVerifyInit()
151 */
152 if (ret <= 0)
153 ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,153,__func__), ERR_set_error)((13),((6 | (0x2 << 18L))
),((void*)0))
;
154 if (ret <= 1)
155 goto err;
156 } else {
157 const EVP_MD *type = NULL((void*)0);
158
159 /*
160 * We don't yet have the ability for providers to be able to handle
161 * X509_ALGOR style parameters. Fortunately the only one that needs this
162 * so far is RSA-PSS, so we just special case this for now. In some
163 * future version of OpenSSL we should push this to the provider.
164 */
165 if (mdnid == NID_undef0 && pknid == EVP_PKEY_RSA_PSS912) {
166 if (!EVP_PKEY_is_a(pkey, "RSA") && !EVP_PKEY_is_a(pkey, "RSA-PSS")) {
167 ERR_raise(ERR_LIB_ASN1, ASN1_R_WRONG_PUBLIC_KEY_TYPE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,167,__func__), ERR_set_error)((13),(200),((void*)0))
;
168 goto err;
169 }
170 /* This function also calls EVP_DigestVerifyInit */
171 if (ossl_rsa_pss_to_ctx(ctx, NULL((void*)0), alg, pkey) <= 0) {
172 ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,172,__func__), ERR_set_error)((13),((259|((0x1 << 18L)
|(0x2 << 18L)))),((void*)0))
;
173 goto err;
174 }
175 } else {
176 /* Check public key OID matches public key type */
177 if (!EVP_PKEY_is_a(pkey, OBJ_nid2sn(pknid))) {
178 ERR_raise(ERR_LIB_ASN1, ASN1_R_WRONG_PUBLIC_KEY_TYPE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,178,__func__), ERR_set_error)((13),(200),((void*)0))
;
179 goto err;
180 }
181
182 if (mdnid != NID_undef0) {
183 type = EVP_get_digestbynid(mdnid)EVP_get_digestbyname(OBJ_nid2sn(mdnid));
184 if (type == NULL((void*)0)) {
185 ERR_raise(ERR_LIB_ASN1,(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,186,__func__), ERR_set_error)((13),(161),((void*)0))
186 ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,186,__func__), ERR_set_error)((13),(161),((void*)0))
;
187 goto err;
188 }
189 }
190
191 /*
192 * Note that some algorithms (notably Ed25519 and Ed448) may allow
193 * a NULL digest value.
194 */
195 if (!EVP_DigestVerifyInit(ctx, NULL((void*)0), type, NULL((void*)0), pkey)) {
196 ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,196,__func__), ERR_set_error)((13),((6 | (0x2 << 18L))
),((void*)0))
;
197 ret = 0;
198 goto err;
199 }
200 }
201 }
202
203 inl = ASN1_item_i2d(data, &buf_in, it);
204 if (inl <= 0) {
205 ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,205,__func__), ERR_set_error)((13),((259|((0x1 << 18L)
|(0x2 << 18L)))),((void*)0))
;
206 goto err;
207 }
208 if (buf_in == NULL((void*)0)) {
209 ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,209,__func__), ERR_set_error)((13),((256|((0x1 << 18L)
|(0x2 << 18L)))),((void*)0))
;
210 goto err;
211 }
212 inll = inl;
213
214 ret = EVP_DigestVerify(ctx, signature->data, (size_t)signature->length,
215 buf_in, inl);
216 if (ret <= 0) {
217 ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/crypto/asn1/a_verify.c"
,217,__func__), ERR_set_error)((13),((6 | (0x2 << 18L))
),((void*)0))
;
218 goto err;
219 }
220 ret = 1;
221 err:
222 OPENSSL_clear_free(buf_in, inll)CRYPTO_clear_free(buf_in, inll, "../deps/openssl/openssl/crypto/asn1/a_verify.c"
, 222)
;
223 return ret;
224}