Skip to content

Commit 3120dac

Browse files
committed
Add new make cppcheck option. Fixes for cppcheck. Added missing wolfssl-v4.7.0.patch
1 parent 48eca3c commit 3120dac

6 files changed

Lines changed: 45 additions & 11 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/src/tls13.c b/src/tls13.c
2+
index b2fd50f2f..bcc912890 100644
3+
--- a/src/tls13.c
4+
+++ b/src/tls13.c
5+
@@ -421,6 +421,14 @@ static int DeriveKey(WOLFSSL* ssl, byte* output, int outputLen,
6+
outputLen = hashSz;
7+
if (includeMsgs)
8+
hashOutSz = hashSz;
9+
+ else {
10+
+ /* Appease static analyzers by making sure hash is cleared, since it is
11+
+ * passed into expand key label where older wc_Tls13_HKDF_Expand_Label
12+
+ * will unconditionally try to call a memcpy on it, however length will
13+
+ * always be 0. */
14+
+ XMEMSET(hash, 0, sizeof(hash));
15+
+ hashOutSz = 0;
16+
+ }
17+
18+
return HKDF_Expand_Label(output, outputLen, secret, hashSz,
19+
protocol, protocolLen, label, labelLen,

Makefile.am

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ merge-clean:
116116
@find ./ | $(GREP) \.OTHER | xargs rm -f
117117
@find ./ | $(GREP) \.BASE | xargs rm -f
118118
@find ./ | $(GREP) \~$$ | xargs rm -f
119+
120+
cppcheck:
121+
@if test "x@CPPCHECK@" = "xno"; then \
122+
echo "Error: cppcheck not found. Please install cppcheck."; \
123+
exit 1; \
124+
fi
125+
@CPPCHECK@ -f --enable=warning \
126+
--enable=portability --check-level=exhaustive \
127+
--suppress=invalidPrintfArgType_sint \
128+
--error-exitcode=89 --std=c89 \
129+
-I wolftpm src/ hal/ examples

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ fi
466466
# HARDEN FLAGS
467467
AX_HARDEN_CC_COMPILER_FLAGS
468468

469+
# Check for cppcheck (optional, for make cppcheck target)
470+
AC_CHECK_PROG([CPPCHECK], [cppcheck], [cppcheck], [no])
471+
AM_CONDITIONAL([HAVE_CPPCHECK], [test "x$CPPCHECK" != "xno"])
472+
469473
OPTION_FLAGS="$CFLAGS $CPPFLAGS $AM_CFLAGS"
470474

471475

@@ -494,6 +498,7 @@ CREATE_HEX_VERSION
494498
AC_SUBST([AM_CPPFLAGS])
495499
AC_SUBST([AM_CFLAGS])
496500
AC_SUBST([AM_LDFLAGS])
501+
AC_SUBST([CPPCHECK])
497502

498503
# FINAL
499504
AC_CONFIG_FILES([Makefile])

examples/keygen/keyimport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[])
149149
printf("\tAlgorithm: %s\n", TPM2_GetAlgName(alg));
150150
printf("\tSRK: %s\n", TPM2_GetAlgName(srkAlg));
151151
printf("\tUse Parameter Encryption: %s\n", TPM2_GetAlgName(paramEncAlg));
152-
printf("\tpassword: %s\n", password);
152+
if (password != NULL) {
153+
printf("\tpassword: %s\n", password);
154+
}
153155

154156
rc = wolfTPM2_Init(&dev, TPM2_IoCb, userCtx);
155157
if (rc != TPM_RC_SUCCESS) {

examples/pcr/extend.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ int TPM2_PCR_Extend_Test(void* userCtx, int argc, char *argv[])
149149
/* Prepare the hash from user file or predefined value */
150150
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) && \
151151
!defined(WOLFTPM2_NO_WOLFCRYPT)
152-
if (filename) {
153-
fp = XFOPEN(filename, "rb");
154-
}
155-
if (filename && fp != XBADFILE) {
152+
fp = XFOPEN(filename, "rb");
153+
if (fp != XBADFILE) {
156154
rc = TPM2_GetHashType(alg);
157155
hashType = (enum wc_HashType)rc;
158156
wc_HashInit(&dig, hashType);

src/tpm2_wrap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ int wolfTPM2_ComputeName(const TPM2B_PUBLIC* pub, TPM2B_NAME* out)
21672167
#ifndef WOLFTPM2_NO_WOLFCRYPT
21682168
/* Encode public into buffer */
21692169
XMEMSET(&packet, 0, sizeof(packet));
2170+
XMEMSET(&data, 0, sizeof(data));
21702171
packet.buf = data.buffer;
21712172
packet.size = sizeof(data.buffer);
21722173
TPM2_Packet_AppendPublicArea(&packet, (TPMT_PUBLIC*)&pub->publicArea);
@@ -7551,12 +7552,10 @@ int wolfTPM2_CSR_SetKeyUsage(WOLFTPM2_DEV* dev, WOLFTPM2_CSR* csr,
75517552
rc = wc_SetKeyUsage(&csr->req, keyUsage);
75527553
}
75537554
#else
7554-
if (keyUsage != NULL) {
7555-
#ifdef DEBUG_WOLFTPM
7556-
printf("CSR_Generate key usage supplied, but not available\n");
7557-
#endif
7558-
rc = NOT_COMPILED_IN;
7559-
}
7555+
#ifdef DEBUG_WOLFTPM
7556+
printf("CSR_Generate key usage supplied, but not available\n");
7557+
#endif
7558+
rc = NOT_COMPILED_IN;
75607559
#endif
75617560
(void)dev; /* not used */
75627561
return rc;

0 commit comments

Comments
 (0)