Skip to content

Commit

Permalink
CryptoPkg: More CodeQL fixes (#320)
Browse files Browse the repository at this point in the history
## Description

Various fixes

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [x] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Build and boot changes on QemuQ35Pkg to EFI shell.

## Integration Instructions

N/A
  • Loading branch information
TaylorBeebe authored and kenlautner committed Oct 18, 2023
1 parent 314b1f8 commit 9c4d74d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ AuthenticodeVerify (
// PKCS#7 ContentInfo here.
//
SpcIndirectDataOid = OBJ_get0_data (Pkcs7->d.sign->contents->type);
// MU_CHANGE [BEGIN] - CodeQL change
if (SpcIndirectDataOid == NULL) {
goto _Exit;
}

// MU_CHANGE [END] - CodeQL change
if ((OBJ_length (Pkcs7->d.sign->contents->type) != sizeof (mSpcIndirectOidValue)) ||
(CompareMem (
SpcIndirectDataOid,
Expand Down
12 changes: 10 additions & 2 deletions CryptoPkg/Library/BaseCryptLib/Pk/CryptDh.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ DhSetParameter (
return TRUE;

Error:
BN_free (BnP);
BN_free (BnG);
// MU_CHANGE [BEGIN] - CodeQL change
if (BnP != NULL) {
BN_free (BnP);
}

if (BnG != NULL) {
BN_free (BnG);
}

// MU_CHANGE [END] - CodeQL change

return FALSE;
}
Expand Down
6 changes: 6 additions & 0 deletions CryptoPkg/Library/BaseCryptLib/Pk/CryptTs.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ CheckTSTInfo (
//
Imprint = TstInfo->MessageImprint;
HashAlgo = X509_ALGOR_dup (Imprint->HashAlgorithm);
// MU_CHANGE [BEGIN] - CodeQL change
if ((HashAlgo == NULL) || (HashAlgo->algorithm == NULL)) {
goto _Exit;
}

// MU_CHANGE [END] - CodeQL change

Md = EVP_get_digestbyobj (HashAlgo->algorithm);
if (Md == NULL) {
Expand Down
15 changes: 15 additions & 0 deletions CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,17 @@ InternalX509GetNIDName (
}

EntryData = X509_NAME_ENTRY_get_data (Entry);
// MU_CHANGE [BEGIN] - CodeQL change
if (EntryData == NULL) {
//
// Fail to retrieve name entry data
//
*CommonNameSize = 0;
ReturnStatus = RETURN_NOT_FOUND;
goto _Exit;
}

// MU_CHANGE [END] - CodeQL change

Length = ASN1_STRING_to_UTF8 (&UTF8Name, EntryData);
if (Length < 0) {
Expand Down Expand Up @@ -809,6 +820,10 @@ X509GetTBSCert (
UINTN Length;
UINTN Inf;

// MU_CHANGE [BEGIN] - CodeQL change
Asn1Tag = (UINT32)V_ASN1_UNDEF;
// MU_CHANGE [END] - CodeQL change

//
// Check input parameters.
//
Expand Down

0 comments on commit 9c4d74d

Please sign in to comment.