Skip to content

Commit

Permalink
Check for null return pointers in pem_test.cc (#1855)
Browse files Browse the repository at this point in the history
### Issues:
Resolves P154590111

### Description of changes: 
Static analysis found a few cases where these tests could fail due to
dereferencing null, if a null pointer ever shows up here the test will
still fail, but now more gracefully.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
  • Loading branch information
andrewhop authored Sep 20, 2024
1 parent c187579 commit e7e48b1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crypto/pem/pem_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,11 @@ TEST(ParametersTest, PEMReadwrite) {
ASSERT_TRUE(pkey_read);

EC_KEY *pkey_eckey = EVP_PKEY_get0_EC_KEY(pkey.get());
ASSERT_TRUE(pkey_eckey);
const EC_GROUP *orig_params = EC_KEY_get0_group(pkey_eckey);
ASSERT_TRUE(orig_params);
const EC_GROUP *read_params = EC_KEY_get0_group(pkey_eckey);
ASSERT_TRUE(read_params);
ASSERT_EQ(0, EC_GROUP_cmp(orig_params, read_params, nullptr));

// Test |PEM_read/write_bio_Parameters| with |DH|.
Expand All @@ -317,6 +320,7 @@ TEST(ParametersTest, PEMReadwrite) {
ASSERT_TRUE(pkey_read);

DH *pkey_dh = EVP_PKEY_get0_DH(pkey.get());
ASSERT_TRUE(pkey_dh);
EXPECT_EQ(0, BN_cmp(DH_get0_p(pkey_dh), DH_get0_p(dh.get())));
EXPECT_EQ(0, BN_cmp(DH_get0_g(pkey_dh), DH_get0_g(dh.get())));

Expand Down

0 comments on commit e7e48b1

Please sign in to comment.