Skip to content

Commit 73887a1

Browse files
committed
Remove wrong null check
1. #552 fix corrected — Removed out == NULL from the guard; outSz == NULL check remains 2. Copilot review: overflow guard in wolfTPM2_UnloadHandles — Added pre-loop handleStart + handleCount overflow check 3. Copilot review: BER indefinite-length — Reject bytes == 0 in TPM2_ASN_GetLength_ex 4. Copilot review: bounds check before X.509 version read — Added len <= 0 || idx >= inputSz check before accessing input[idx] 5. Build fix — Cast inputSz to word32 for sign-compare warning
1 parent 4d1ec8a commit 73887a1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/tpm2_asn.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ int TPM2_ASN_GetLength_ex(const uint8_t* input, word32* inOutIdx, int* len,
5656
b = input[idx++];
5757
if (b >= TPM2_ASN_LONG_LENGTH) {
5858
word32 bytes = b & 0x7F;
59-
if (bytes > 3 || (idx + bytes) > maxIdx) {
59+
/* DER does not allow BER indefinite-length (0x80 => bytes == 0) */
60+
if (bytes == 0 || bytes > 3 || (idx + bytes) > maxIdx) {
6061
return TPM_RC_INSUFFICIENT;
6162
}
6263
while (bytes--) {
@@ -187,6 +188,12 @@ int TPM2_ASN_DecodeX509Cert(uint8_t* input, int inputSz,
187188
&idx, &len, inputSz);
188189
}
189190

191+
if (rc >= 0) {
192+
if (len <= 0 || idx >= (word32)inputSz) {
193+
rc = TPM_RC_VALUE;
194+
}
195+
}
196+
190197
if (rc >= 0) {
191198
/* check version tag is INTEGER */
192199
if (input[idx] != TPM2_ASN_INTEGER) {

src/tpm2_wrap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3277,7 +3277,7 @@ int wolfTPM2_ExportPublicKeyBuffer(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
32773277
#endif
32783278
} key;
32793279

3280-
if (dev == NULL || tpmKey == NULL || out == NULL || outSz == NULL) {
3280+
if (dev == NULL || tpmKey == NULL || outSz == NULL) {
32813281
return BAD_FUNC_ARG;
32823282
}
32833283

@@ -6295,6 +6295,9 @@ int wolfTPM2_UnloadHandles(WOLFTPM2_DEV* dev, word32 handleStart,
62956295
if (dev == NULL) {
62966296
return BAD_FUNC_ARG;
62976297
}
6298+
if (handleCount != 0 && handleStart > (word32)0xFFFFFFFF - (handleCount - 1)) {
6299+
return BAD_FUNC_ARG;
6300+
}
62986301
XMEMSET(&handle, 0, sizeof(handle));
62996302
wolfTPM2_CopyAuth(&handle.auth, &dev->session[0].auth);
63006303

0 commit comments

Comments
 (0)