Skip to content

Commit

Permalink
Prevent accidental null dereference (#2046)
Browse files Browse the repository at this point in the history
  • Loading branch information
torben-hansen authored Dec 10, 2024
1 parent b649c44 commit 1f5bee2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions crypto/cipher_extra/cipher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,9 @@ TEST(CipherTest, GetCipher) {
EXPECT_FALSE(EVP_get_cipherbyname(nullptr));
EXPECT_FALSE(EVP_get_cipherbyname("vigenère"));
EXPECT_FALSE(EVP_get_cipherbynid(-1));
EXPECT_FALSE(EVP_CIPHER_block_size(nullptr));
EXPECT_FALSE(EVP_CIPHER_key_length(nullptr));
EXPECT_FALSE(EVP_CIPHER_iv_length(nullptr));
}

// Test the AES-GCM EVP_CIPHER's internal IV management APIs. OpenSSH uses these
Expand Down
22 changes: 18 additions & 4 deletions crypto/fipsmodule/cipher/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,18 +689,32 @@ int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, unsigned key_len) {
return 1;
}

int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { return cipher->nid; }
int EVP_CIPHER_nid(const EVP_CIPHER *cipher) {
if (cipher != NULL) {
return cipher->nid;
}
return 0;
}

unsigned EVP_CIPHER_block_size(const EVP_CIPHER *cipher) {
return cipher->block_size;
if (cipher != NULL) {
return cipher->block_size;
}
return 0;
}

unsigned EVP_CIPHER_key_length(const EVP_CIPHER *cipher) {
return cipher->key_len;
if (cipher != NULL) {
return cipher->key_len;
}
return 0;
}

unsigned EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) {
return cipher->iv_len;
if (cipher != NULL) {
return cipher->iv_len;
}
return 0;
}

uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) {
Expand Down

0 comments on commit 1f5bee2

Please sign in to comment.