Bug Summary

File:root/firefox-clang/security/nss/lib/pk11wrap/secmodti.h
Warning:line 29, column 8
Excessive padding in 'struct PK11SlotInfoStr' (32 padding bytes, where 0 is optimal). Optimal fields order: functionList, module, flags, session, sessionLock, slotID, defaultFlags, freeListLock, freeSymKeysWithSessionHead, freeSymKeysHead, authTime, wrapMechanism, refKeys, mechanismList, cert_array, RSAInfoFlags, nssTokenLock, nssToken, profileList, validationFIPSFlags, tokenInfo, needTest, isPerm, isHW, isInternal, disabled, reason, readOnly, needLogin, hasRandom, defRWSession, isThreadSafe, refCount, keyCount, maxKeyCount, askpw, timeout, minPassword, maxPassword, flagState, mechanismCount, array_size, cert_count, hasRootCerts, hasRootTrust, hasRSAInfo, protectedAuthPath, isActiveCard, lastState, lastLoginCheck, profileCount, series, flagSeries, wrapKey, serial, token_name, slot_name, mechanismBits, consider reordering the fields or adding explicit padding members

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name dev3hack.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 -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/security/nss/lib/pk11wrap/pk11wrap_pk11wrap -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/security/nss/lib/pk11wrap/pk11wrap_pk11wrap -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG -D SHLIB_SUFFIX="so" -D SHLIB_PREFIX="lib" -D NSS_SHLIB_VERSION="3" -D SOFTOKEN_SHLIB_VERSION="3" -D NSS_FIPS_DISABLED -D NSS_NO_INIT_SUPPORT -D NSS_X86_OR_X64 -D NSS_X64 -D NSS_USE_64 -D USE_UTIL_DIRECTLY -D NO_NSPR_10_SUPPORT -D SSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -D LINUX2_1 -D LINUX -D linux -D _DEFAULT_SOURCE -D _BSD_SOURCE -D _POSIX_SOURCE -D SDB_MEASURE_USE_TEMP_DIR -D HAVE_STRERROR -D XP_UNIX -D _REENTRANT -D NSS_DISABLE_DBM -D NSS_DISABLE_LIBPKIX -D NSS_USE_PKCS5_PBKD2_PARAMS2_ONLY -D SOFTOKEN_USE_PKCS5_PBKD2_PARAMS2_ONLY -I /root/firefox-clang/security/nss/lib/pk11wrap -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/security/nss/lib/pk11wrap/pk11wrap_pk11wrap -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/private/nss -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-10-17-231001-351276-1 -x c /root/firefox-clang/security/nss/lib/pk11wrap/dev3hack.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 * Internal header file included only by files in pkcs11 dir, or in
6 * pkcs11 specific client and server files.
7 */
8
9#ifndef _SECMODTI_H_1
10#define _SECMODTI_H_1 1
11#include "prmon.h"
12#include "prtypes.h"
13#include "secmodt.h"
14#include "pkcs11t.h"
15
16#include "nssdevt.h"
17
18/* internal data structures */
19
20/* Traverse slots callback */
21typedef struct pk11TraverseSlotStr {
22 SECStatus (*callback)(PK11SlotInfo *, CK_OBJECT_HANDLE, void *);
23 void *callbackArg;
24 CK_ATTRIBUTE *findTemplate;
25 int templateCount;
26} pk11TraverseSlot;
27
28/* represent a pkcs#11 slot reference counted. */
29struct PK11SlotInfoStr {
Excessive padding in 'struct PK11SlotInfoStr' (32 padding bytes, where 0 is optimal). Optimal fields order: functionList, module, flags, session, sessionLock, slotID, defaultFlags, freeListLock, freeSymKeysWithSessionHead, freeSymKeysHead, authTime, wrapMechanism, refKeys, mechanismList, cert_array, RSAInfoFlags, nssTokenLock, nssToken, profileList, validationFIPSFlags, tokenInfo, needTest, isPerm, isHW, isInternal, disabled, reason, readOnly, needLogin, hasRandom, defRWSession, isThreadSafe, refCount, keyCount, maxKeyCount, askpw, timeout, minPassword, maxPassword, flagState, mechanismCount, array_size, cert_count, hasRootCerts, hasRootTrust, hasRSAInfo, protectedAuthPath, isActiveCard, lastState, lastLoginCheck, profileCount, series, flagSeries, wrapKey, serial, token_name, slot_name, mechanismBits, consider reordering the fields or adding explicit padding members
30 /* the PKCS11 function list for this slot */
31 void *functionList;
32 SECMODModule *module; /* our parent module */
33 /* Boolean to indicate the current state of this slot */
34 PRBool needTest; /* Has this slot been tested for Export complience */
35 PRBool isPerm; /* is this slot a permanment device */
36 PRBool isHW; /* is this slot a hardware device */
37 PRBool isInternal; /* is this slot one of our internal PKCS #11 devices */
38 PRBool disabled; /* is this slot disabled... */
39 PK11DisableReasons reason; /* Why this slot is disabled */
40 PRBool readOnly; /* is the token in this slot read-only */
41 PRBool needLogin; /* does the token of the type that needs
42 * authentication (still true even if token is logged
43 * in) */
44 PRBool hasRandom; /* can this token generated random numbers */
45 PRBool defRWSession; /* is the default session RW (we open our default
46 * session rw if the token can only handle one session
47 * at a time. */
48 PRBool isThreadSafe; /* copied from the module */
49 /* The actual flags (many of which are distilled into the above PRBools) */
50 CK_FLAGS flags; /* flags from PKCS #11 token Info */
51 /* a default session handle to do quick and dirty functions */
52 CK_SESSION_HANDLE session;
53 PRLock *sessionLock; /* lock for this session */
54 /* our ID */
55 CK_SLOT_ID slotID;
56 /* persistant flags saved from startup to startup */
57 unsigned long defaultFlags;
58 /* keep track of who is using us so we don't accidently get freed while
59 * still in use */
60 PRInt32 refCount; /* to be in/decremented by atomic calls ONLY! */
61
62 // freeListLock protects freeSymKeysWithSessionHead, freeSymKeysHead,
63 // keyCount, and maxKeyCount.
64 PRLock *freeListLock;
65 PK11SymKey *freeSymKeysWithSessionHead;
66 PK11SymKey *freeSymKeysHead;
67 int keyCount;
68 int maxKeyCount;
69
70 /* Password control functions for this slot. many of these are only
71 * active if the appropriate flag is on in defaultFlags */
72 int askpw; /* what our password options are */
73 int timeout; /* If we're ask_timeout, what is our timeout time is
74 * seconds */
75 PRTime authTime; /* when were we last authenticated */
76 int minPassword; /* smallest legal password */
77 int maxPassword; /* largest legal password */
78 PRUint16 series; /* break up the slot info into various groups of
79 * inserted tokens so that keys and certs can be
80 * invalidated */
81 PRUint16 flagSeries; /* record the last series for the last event
82 * returned for this slot */
83 PRBool flagState; /* record the state of the last event returned for this
84 * slot. */
85 PRUint16 wrapKey; /* current wrapping key for SSL master secrets */
86 CK_MECHANISM_TYPE wrapMechanism;
87 /* current wrapping mechanism for current wrapKey */
88 CK_OBJECT_HANDLE refKeys[1]; /* array of existing wrapping keys for */
89 CK_MECHANISM_TYPE *mechanismList; /* list of mechanism supported by this
90 * token */
91 int mechanismCount;
92 /* cache the certificates stored on the token of this slot */
93 CERTCertificate **cert_array;
94 int array_size;
95 int cert_count;
96 char serial[16];
97 /* since these are odd sizes, keep them last. They are odd sizes to
98 * allow them to become null terminated strings */
99 char slot_name[65];
100 char token_name[33];
101 PRBool hasRootCerts;
102 PRBool hasRootTrust;
103 PRBool hasRSAInfo;
104 CK_FLAGS RSAInfoFlags;
105 PRBool protectedAuthPath;
106 PRBool isActiveCard;
107 unsigned int lastState;
108
109 /* nssTokenLock protects nssToken and lastLoginCheck */
110 PRLock *nssTokenLock;
111 NSSToken *nssToken;
112 PRIntervalTime lastLoginCheck;
113
114 /* the tokeninfo struct */
115 CK_TOKEN_INFO tokenInfo;
116 /* fast mechanism lookup */
117 char mechanismBits[256];
118 CK_PROFILE_ID *profileList;
119 int profileCount;
120 CK_FLAGS validationFIPSFlags;
121};
122
123/* Symetric Key structure. Reference Counted */
124struct PK11SymKeyStr {
125 CK_MECHANISM_TYPE type; /* type of operation this key was created for*/
126 CK_OBJECT_HANDLE objectID; /* object id of this key in the slot */
127 PK11SlotInfo *slot; /* Slot this key is loaded into */
128 void *cx; /* window context in case we need to loggin */
129 PK11SymKey *next;
130 PRBool owner;
131 SECItem data; /* raw key data if available */
132 CK_SESSION_HANDLE session;
133 PRBool sessionOwner;
134 PRInt32 refCount; /* number of references to this key */
135 int size; /* key size in bytes */
136 PK11Origin origin; /* where this key came from
137 * (see def in secmodt.h) */
138 PK11SymKey *parent; /* potential owner key of the session */
139 PRUint16 series; /* break up the slot info into various groups
140 * of inserted tokens so that keys and certs
141 * can be invalidated */
142 void *userData; /* random data the application can attach to
143 * this key */
144 PK11FreeDataFunc freeFunc; /* function to free the user data */
145};
146
147/*
148 * hold a hash, encryption or signing context for multi-part operations.
149 * hold enough information so that multiple contexts can be interleaved
150 * if necessary. ... Not RefCounted.
151 */
152struct PK11ContextStr {
153 CK_ATTRIBUTE_TYPE operation; /* type of operation this context is
154 * doing (CKA_ENCRYPT, CKA_SIGN,
155 * CKA_HASH, etc.) */
156 PK11SymKey *key; /* symetric key for this context */
157 CK_OBJECT_HANDLE objectID; /* object handle to key */
158 PK11SlotInfo *slot; /* slot this context is using */
159 CK_SESSION_HANDLE session; /* session this context is using */
160 PRLock *sessionLock; /* lock before accessing a PKCS #11
161 * session */
162 PRBool ownSession; /* do we own the session? */
163 void *pwArg; /* applicaton specific passwd arg */
164 void *savedData; /* save data when we are
165 * multiplexing on a single context */
166 unsigned long savedLength; /* length of the saved context */
167 SECItem *param; /* mechanism parameters used to
168 * build this context */
169 PRBool init; /* this contexted been initialized? */
170 CK_MECHANISM_TYPE type; /* what is the PKCS #11 this context
171 * is representing (usually what
172 * algorithm is being used
173 * (CKM_RSA_PKCS, CKM_DES, CKM_SHA,
174 * etc. */
175 PRBool fortezzaHack; /* Fortezza SSL has some special
176 * non-standard semantics*/
177 PRBool simulate_message; /* We are initializing a message
178 * interface but the underlying
179 * PKCS #11 module does not support
180 * it. We simulate the interface with
181 * the PCKS #11 v2 interface */
182 CK_MECHANISM_TYPE simulate_mechanism; /* The mechanism we are simulating */
183 PRUint64 ivCounter; /* iv counter for simulated message */
184 PRUint64 ivMaxCount; /* total number of IVs valid for
185 * this key */
186 unsigned long ivLen; /* length of the iv in bytes */
187 unsigned int ivFixedBits; /* number of bits not generated
188 * for the iv */
189 CK_GENERATOR_FUNCTION ivGen; /* PKCS #11 iv generator value */
190};
191
192/*
193 * structure to hold a pointer to a unique PKCS #11 object
194 * (pointer to the slot and the object id).
195 */
196struct PK11GenericObjectStr {
197 PK11GenericObject *prev;
198 PK11GenericObject *next;
199 PK11SlotInfo *slot;
200 CK_OBJECT_HANDLE objectID;
201 PRBool owner;
202};
203
204#define MAX_TEMPL_ATTRS16 16 /* maximum attributes in template */
205
206/* This mask includes all CK_FLAGs with an equivalent CKA_ attribute. */
207#define CKF_KEY_OPERATION_FLAGS0x000e7b00UL 0x000e7b00UL
208
209#endif /* _SECMODTI_H_ */