Bug Summary

File:out/../deps/openssl/openssl/crypto/txt_db/txt_db.c
Warning:line 83, column 9
Value stored to 'i' 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 txt_db.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/txt_db/txt_db.c
1/*
2 * Copyright 1995-2018 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 <stdlib.h>
12#include <string.h>
13#include "internal/cryptlib.h"
14#include <openssl/buffer.h>
15#include <openssl/txt_db.h>
16
17#undef BUFSIZE512
18#define BUFSIZE512 512
19
20TXT_DB *TXT_DB_read(BIO *in, int num)
21{
22 TXT_DB *ret = NULL((void*)0);
23 int esc = 0;
24 long ln = 0;
25 int i, add, n;
26 int size = BUFSIZE512;
27 int offset = 0;
28 char *p, *f;
29 OPENSSL_STRING *pp;
30 BUF_MEM *buf = NULL((void*)0);
31
32 if ((buf = BUF_MEM_new()) == NULL((void*)0))
33 goto err;
34 if (!BUF_MEM_grow(buf, size))
35 goto err;
36
37 if ((ret = OPENSSL_malloc(sizeof(*ret))CRYPTO_malloc(sizeof(*ret), "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 37)
) == NULL((void*)0))
38 goto err;
39 ret->num_fields = num;
40 ret->index = NULL((void*)0);
41 ret->qual = NULL((void*)0);
42 if ((ret->data = sk_OPENSSL_PSTRING_new_null()) == NULL((void*)0))
43 goto err;
44 if ((ret->index = OPENSSL_malloc(sizeof(*ret->index) * num)CRYPTO_malloc(sizeof(*ret->index) * num, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 44)
) == NULL((void*)0))
45 goto err;
46 if ((ret->qual = OPENSSL_malloc(sizeof(*(ret->qual)) * num)CRYPTO_malloc(sizeof(*(ret->qual)) * num, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 46)
) == NULL((void*)0))
47 goto err;
48 for (i = 0; i < num; i++) {
49 ret->index[i] = NULL((void*)0);
50 ret->qual[i] = NULL((void*)0);
51 }
52
53 add = (num + 1) * sizeof(char *);
54 buf->data[size - 1] = '\0';
55 offset = 0;
56 for (;;) {
57 if (offset != 0) {
58 size += BUFSIZE512;
59 if (!BUF_MEM_grow_clean(buf, size))
60 goto err;
61 }
62 buf->data[offset] = '\0';
63 BIO_gets(in, &(buf->data[offset]), size - offset);
64 ln++;
65 if (buf->data[offset] == '\0')
66 break;
67 if ((offset == 0) && (buf->data[0] == '#'))
68 continue;
69 i = strlen(&(buf->data[offset]));
70 offset += i;
71 if (buf->data[offset - 1] != '\n')
72 continue;
73 else {
74 buf->data[offset - 1] = '\0'; /* blat the '\n' */
75 if ((p = OPENSSL_malloc(add + offset)CRYPTO_malloc(add + offset, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 75)
) == NULL((void*)0))
76 goto err;
77 offset = 0;
78 }
79 pp = (char **)p;
80 p += add;
81 n = 0;
82 pp[n++] = p;
83 i = 0;
Value stored to 'i' is never read
84 f = buf->data;
85
86 esc = 0;
87 for (;;) {
88 if (*f == '\0')
89 break;
90 if (*f == '\t') {
91 if (esc)
92 p--;
93 else {
94 *(p++) = '\0';
95 f++;
96 if (n >= num)
97 break;
98 pp[n++] = p;
99 continue;
100 }
101 }
102 esc = (*f == '\\');
103 *(p++) = *(f++);
104 }
105 *(p++) = '\0';
106 if ((n != num) || (*f != '\0')) {
107 OPENSSL_free(pp)CRYPTO_free(pp, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 107)
;
108 ret->error = DB_ERROR_WRONG_NUM_FIELDS6;
109 goto err;
110 }
111 pp[n] = p;
112 if (!sk_OPENSSL_PSTRING_push(ret->data, pp)) {
113 OPENSSL_free(pp)CRYPTO_free(pp, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 113)
;
114 goto err;
115 }
116 }
117 BUF_MEM_free(buf);
118 return ret;
119 err:
120 BUF_MEM_free(buf);
121 if (ret != NULL((void*)0)) {
122 sk_OPENSSL_PSTRING_free(ret->data);
123 OPENSSL_free(ret->index)CRYPTO_free(ret->index, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 123)
;
124 OPENSSL_free(ret->qual)CRYPTO_free(ret->qual, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 124)
;
125 OPENSSL_free(ret)CRYPTO_free(ret, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 125)
;
126 }
127 return NULL((void*)0);
128}
129
130OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx,
131 OPENSSL_STRING *value)
132{
133 OPENSSL_STRING *ret;
134 LHASH_OF(OPENSSL_STRING)struct lhash_st_OPENSSL_STRING *lh;
135
136 if (idx >= db->num_fields) {
137 db->error = DB_ERROR_INDEX_OUT_OF_RANGE3;
138 return NULL((void*)0);
139 }
140 lh = db->index[idx];
141 if (lh == NULL((void*)0)) {
142 db->error = DB_ERROR_NO_INDEX4;
143 return NULL((void*)0);
144 }
145 ret = lh_OPENSSL_STRING_retrieve(lh, value)((OPENSSL_STRING *)OPENSSL_LH_retrieve(ossl_check_OPENSSL_STRING_lh_type
(lh), ossl_check_const_OPENSSL_STRING_lh_plain_type(value)))
;
146 db->error = DB_ERROR_OK0;
147 return ret;
148}
149
150int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *),
151 OPENSSL_LH_HASHFUNC hash, OPENSSL_LH_COMPFUNC cmp)
152{
153 LHASH_OF(OPENSSL_STRING)struct lhash_st_OPENSSL_STRING *idx;
154 OPENSSL_STRING *r, *k;
155 int i, n;
156
157 if (field >= db->num_fields) {
158 db->error = DB_ERROR_INDEX_OUT_OF_RANGE3;
159 return 0;
160 }
161 /* FIXME: we lose type checking at this point */
162 if ((idx = (LHASH_OF(OPENSSL_STRING)struct lhash_st_OPENSSL_STRING *)OPENSSL_LH_new(hash, cmp)) == NULL((void*)0)) {
163 db->error = DB_ERROR_MALLOC1;
164 return 0;
165 }
166 n = sk_OPENSSL_PSTRING_num(db->data);
167 for (i = 0; i < n; i++) {
168 r = sk_OPENSSL_PSTRING_value(db->data, i);
169 if ((qual != NULL((void*)0)) && (qual(r) == 0))
170 continue;
171 if ((k = lh_OPENSSL_STRING_insert(idx, r)((OPENSSL_STRING *)OPENSSL_LH_insert(ossl_check_OPENSSL_STRING_lh_type
(idx), ossl_check_OPENSSL_STRING_lh_plain_type(r)))
) != NULL((void*)0)) {
172 db->error = DB_ERROR_INDEX_CLASH2;
173 db->arg1 = sk_OPENSSL_PSTRING_find(db->data, k);
174 db->arg2 = i;
175 lh_OPENSSL_STRING_free(idx)OPENSSL_LH_free(ossl_check_OPENSSL_STRING_lh_type(idx));
176 return 0;
177 }
178 if (lh_OPENSSL_STRING_retrieve(idx, r)((OPENSSL_STRING *)OPENSSL_LH_retrieve(ossl_check_OPENSSL_STRING_lh_type
(idx), ossl_check_const_OPENSSL_STRING_lh_plain_type(r)))
== NULL((void*)0)) {
179 db->error = DB_ERROR_MALLOC1;
180 lh_OPENSSL_STRING_free(idx)OPENSSL_LH_free(ossl_check_OPENSSL_STRING_lh_type(idx));
181 return 0;
182 }
183 }
184 lh_OPENSSL_STRING_free(db->index[field])OPENSSL_LH_free(ossl_check_OPENSSL_STRING_lh_type(db->index
[field]))
;
185 db->index[field] = idx;
186 db->qual[field] = qual;
187 return 1;
188}
189
190long TXT_DB_write(BIO *out, TXT_DB *db)
191{
192 long i, j, n, nn, l, tot = 0;
193 char *p, **pp, *f;
194 BUF_MEM *buf = NULL((void*)0);
195 long ret = -1;
196
197 if ((buf = BUF_MEM_new()) == NULL((void*)0))
198 goto err;
199 n = sk_OPENSSL_PSTRING_num(db->data);
200 nn = db->num_fields;
201 for (i = 0; i < n; i++) {
202 pp = sk_OPENSSL_PSTRING_value(db->data, i);
203
204 l = 0;
205 for (j = 0; j < nn; j++) {
206 if (pp[j] != NULL((void*)0))
207 l += strlen(pp[j]);
208 }
209 if (!BUF_MEM_grow_clean(buf, (int)(l * 2 + nn)))
210 goto err;
211
212 p = buf->data;
213 for (j = 0; j < nn; j++) {
214 f = pp[j];
215 if (f != NULL((void*)0))
216 for (;;) {
217 if (*f == '\0')
218 break;
219 if (*f == '\t')
220 *(p++) = '\\';
221 *(p++) = *(f++);
222 }
223 *(p++) = '\t';
224 }
225 p[-1] = '\n';
226 j = p - buf->data;
227 if (BIO_write(out, buf->data, (int)j) != j)
228 goto err;
229 tot += j;
230 }
231 ret = tot;
232 err:
233 BUF_MEM_free(buf);
234 return ret;
235}
236
237int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)
238{
239 int i;
240 OPENSSL_STRING *r;
241
242 for (i = 0; i < db->num_fields; i++) {
243 if (db->index[i] != NULL((void*)0)) {
244 if ((db->qual[i] != NULL((void*)0)) && (db->qual[i] (row) == 0))
245 continue;
246 r = lh_OPENSSL_STRING_retrieve(db->index[i], row)((OPENSSL_STRING *)OPENSSL_LH_retrieve(ossl_check_OPENSSL_STRING_lh_type
(db->index[i]), ossl_check_const_OPENSSL_STRING_lh_plain_type
(row)))
;
247 if (r != NULL((void*)0)) {
248 db->error = DB_ERROR_INDEX_CLASH2;
249 db->arg1 = i;
250 db->arg_row = r;
251 goto err;
252 }
253 }
254 }
255
256 for (i = 0; i < db->num_fields; i++) {
257 if (db->index[i] != NULL((void*)0)) {
258 if ((db->qual[i] != NULL((void*)0)) && (db->qual[i] (row) == 0))
259 continue;
260 (void)lh_OPENSSL_STRING_insert(db->index[i], row)((OPENSSL_STRING *)OPENSSL_LH_insert(ossl_check_OPENSSL_STRING_lh_type
(db->index[i]), ossl_check_OPENSSL_STRING_lh_plain_type(row
)))
;
261 if (lh_OPENSSL_STRING_retrieve(db->index[i], row)((OPENSSL_STRING *)OPENSSL_LH_retrieve(ossl_check_OPENSSL_STRING_lh_type
(db->index[i]), ossl_check_const_OPENSSL_STRING_lh_plain_type
(row)))
== NULL((void*)0))
262 goto err1;
263 }
264 }
265 if (!sk_OPENSSL_PSTRING_push(db->data, row))
266 goto err1;
267 return 1;
268
269 err1:
270 db->error = DB_ERROR_MALLOC1;
271 while (i-- > 0) {
272 if (db->index[i] != NULL((void*)0)) {
273 if ((db->qual[i] != NULL((void*)0)) && (db->qual[i] (row) == 0))
274 continue;
275 (void)lh_OPENSSL_STRING_delete(db->index[i], row)((OPENSSL_STRING *)OPENSSL_LH_delete(ossl_check_OPENSSL_STRING_lh_type
(db->index[i]), ossl_check_const_OPENSSL_STRING_lh_plain_type
(row)))
;
276 }
277 }
278 err:
279 return 0;
280}
281
282void TXT_DB_free(TXT_DB *db)
283{
284 int i, n;
285 char **p, *max;
286
287 if (db == NULL((void*)0))
288 return;
289 if (db->index != NULL((void*)0)) {
290 for (i = db->num_fields - 1; i >= 0; i--)
291 lh_OPENSSL_STRING_free(db->index[i])OPENSSL_LH_free(ossl_check_OPENSSL_STRING_lh_type(db->index
[i]))
;
292 OPENSSL_free(db->index)CRYPTO_free(db->index, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 292)
;
293 }
294 OPENSSL_free(db->qual)CRYPTO_free(db->qual, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 294)
;
295 if (db->data != NULL((void*)0)) {
296 for (i = sk_OPENSSL_PSTRING_num(db->data) - 1; i >= 0; i--) {
297 /*
298 * check if any 'fields' have been allocated from outside of the
299 * initial block
300 */
301 p = sk_OPENSSL_PSTRING_value(db->data, i);
302 max = p[db->num_fields]; /* last address */
303 if (max == NULL((void*)0)) { /* new row */
304 for (n = 0; n < db->num_fields; n++)
305 OPENSSL_free(p[n])CRYPTO_free(p[n], "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 305)
;
306 } else {
307 for (n = 0; n < db->num_fields; n++) {
308 if (((p[n] < (char *)p) || (p[n] > max)))
309 OPENSSL_free(p[n])CRYPTO_free(p[n], "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 309)
;
310 }
311 }
312 OPENSSL_free(sk_OPENSSL_PSTRING_value(db->data, i))CRYPTO_free(sk_OPENSSL_PSTRING_value(db->data, i), "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 312)
;
313 }
314 sk_OPENSSL_PSTRING_free(db->data);
315 }
316 OPENSSL_free(db)CRYPTO_free(db, "../deps/openssl/openssl/crypto/txt_db/txt_db.c"
, 316)
;
317}