Bug Summary

File:s/cmd/atob/atob.c
Warning:line 126, column 13
Although the value stored to 'status' is used in the enclosing expression, the value is never actually read from 'status'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name atob.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 -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -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 -fdebug-compilation-dir=/var/lib/jenkins/workspace/nss-scan-build/nss/cmd/atob -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/var/lib/jenkins/workspace/nss-scan-build/nss/cmd/atob -resource-dir /usr/lib/llvm-18/lib/clang/18 -D HAVE_STRERROR -D LINUX -D linux -D XP_UNIX -D XP_UNIX -D NSPR20 -D DEBUG -U NDEBUG -D _DEFAULT_SOURCE -D _BSD_SOURCE -D _POSIX_SOURCE -D SDB_MEASURE_USE_TEMP_DIR -D _REENTRANT -D DEBUG -U NDEBUG -D _DEFAULT_SOURCE -D _BSD_SOURCE -D _POSIX_SOURCE -D SDB_MEASURE_USE_TEMP_DIR -D _REENTRANT -D NSS_DISABLE_SSE3 -D NSS_NO_INIT_SUPPORT -D USE_UTIL_DIRECTLY -D NO_NSPR_10_SUPPORT -D SSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -I ../../../dist/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/include -I ../../../dist/public/nss -I ../../../dist/private/nss -I ../../../dist/public/seccmd -I ../../../dist/public/dbm -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c99 -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-18-082241-28900-1 -x c atob.c
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#include "plgetopt.h"
6#include "secutil.h"
7#include "nssb64.h"
8#include <errno(*__errno_location ()).h>
9
10#if defined(XP_WIN) || (defined(__sun) && !defined(SVR4))
11#if !defined(WIN32)
12extern int fread(char *, size_t, size_t, FILE *);
13extern int fwrite(char *, size_t, size_t, FILE *);
14extern int fprintf(FILE *, char *, ...);
15#endif
16#endif
17
18#if defined(WIN32)
19#include "fcntl.h"
20#include "io.h"
21#endif
22
23static PRInt32
24output_binary(void *arg, const unsigned char *obuf, PRInt32 size)
25{
26 FILE *outFile = arg;
27 int nb;
28
29 nb = fwrite(obuf, 1, size, outFile);
30 if (nb != size) {
31 PORT_SetErrorPORT_SetError_Util(SEC_ERROR_IO);
32 return -1;
33 }
34
35 return nb;
36}
37
38static PRBool
39isBase64Char(char c)
40{
41 return ((c >= 'A' && c <= 'Z') ||
42 (c >= 'a' && c <= 'z') ||
43 (c >= '0' && c <= '9') ||
44 c == '+' || c == '/' ||
45 c == '=');
46}
47
48static SECStatus
49decode_file(FILE *outFile, FILE *inFile)
50{
51 NSSBase64Decoder *cx;
52 SECStatus status = SECFailure;
53 char ibuf[4096];
54 const char *ptr;
55
56 cx = NSSBase64Decoder_CreateNSSBase64Decoder_Create_Util(output_binary, outFile);
57 if (!cx) {
58 return -1;
59 }
60
61 for (;;) {
62 if (feof(inFile))
63 break;
64 if (!fgets(ibuf, sizeof(ibuf), inFile)) {
65 if (ferror(inFile)) {
66 PORT_SetErrorPORT_SetError_Util(SEC_ERROR_IO);
67 goto loser;
68 }
69 /* eof */
70 break;
71 }
72 for (ptr = ibuf; *ptr; ++ptr) {
73 char c = *ptr;
74 if (c == '\n' || c == '\r') {
75 break; /* found end of line */
76 }
77 if (!isBase64Char(c)) {
78 ptr = ibuf; /* ignore line */
79 break;
80 }
81 }
82 if (ibuf == ptr) {
83 continue; /* skip empty or non-base64 line */
84 }
85
86 status = NSSBase64Decoder_UpdateNSSBase64Decoder_Update_Util(cx, ibuf, ptr - ibuf);
87 if (status != SECSuccess)
88 goto loser;
89 }
90
91 return NSSBase64Decoder_DestroyNSSBase64Decoder_Destroy_Util(cx, PR_FALSE0);
92
93loser:
94 (void)NSSBase64Decoder_DestroyNSSBase64Decoder_Destroy_Util(cx, PR_TRUE1);
95 return status;
96}
97
98static void
99Usage(char *progName)
100{
101 fprintf(stderrstderr,
102 "Usage: %s [-i input] [-o output]\n",
103 progName);
104 fprintf(stderrstderr, "%-20s Define an input file to use (default is stdin)\n",
105 "-i input");
106 fprintf(stderrstderr, "%-20s Define an output file to use (default is stdout)\n",
107 "-o output");
108}
109
110int
111main(int argc, char **argv)
112{
113 char *progName;
114 SECStatus rv;
115 FILE *inFile = NULL((void*)0), *outFile = NULL((void*)0);
116 PRBool closeIn = PR_TRUE1, closeOut = PR_TRUE1;
117 PLOptState *optstate = NULL((void*)0);
118 PLOptStatus status;
119 int exitCode = -1;
120
121 progName = strrchr(argv[0], '/');
122 progName = progName ? progName + 1 : argv[0];
123
124 /* Parse command line arguments */
125 optstate = PL_CreateOptState(argc, argv, "?hi:o:");
126 while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
Although the value stored to 'status' is used in the enclosing expression, the value is never actually read from 'status'
127 switch (optstate->option) {
128 case '?':
129 case 'h':
130 Usage(progName);
131 goto loser;
132 break;
133
134 case 'i':
135 inFile = fopen(optstate->value, "r");
136 if (!inFile) {
137 fprintf(stderrstderr, "%s: unable to open \"%s\" for reading\n",
138 progName, optstate->value);
139 goto loser;
140 }
141 break;
142
143 case 'o':
144 outFile = fopen(optstate->value, "wb");
145 if (!outFile) {
146 fprintf(stderrstderr, "%s: unable to open \"%s\" for writing\n",
147 progName, optstate->value);
148 goto loser;
149 }
150 break;
151 }
152 }
153 if (!inFile) {
154 inFile = stdinstdin;
155 closeIn = PR_FALSE0;
156 }
157 if (!outFile) {
158#if defined(WIN32)
159 int smrv = _setmode(_fileno(stdoutstdout), _O_BINARY);
160 if (smrv == -1) {
161 fprintf(stderrstderr,
162 "%s: Cannot change stdout to binary mode. Use -o option instead.\n",
163 progName);
164 goto loser;
165 }
166#endif
167 outFile = stdoutstdout;
168 closeOut = PR_FALSE0;
169 }
170 rv = decode_file(outFile, inFile);
171 if (rv != SECSuccess) {
172 fprintf(stderrstderr, "%s: lossage: error=%d errno=%d\n",
173 progName, PORT_GetErrorPORT_GetError_Util(), errno(*__errno_location ()));
174 goto loser;
175 }
176 exitCode = 0;
177loser:
178 if (optstate) {
179 PL_DestroyOptState(optstate);
180 }
181 if (inFile && closeIn) {
182 fclose(inFile);
183 }
184 if (outFile && closeOut) {
185 fclose(outFile);
186 }
187 return exitCode;
188}