-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update EVP cipher APIs to gracefully handle null EVP_CIPHER_CTX (#1398)
### Issues: Resolves V1187459157 ### Description of changes: This change does 3 things: 1. All EVP_CIPHER_CTX now start off as poisoned and require calling EVP_CipherInit_ex to cure it 2. All EVP Encrypt/Decrypt Update/Final now check that the EVP_CIPHER_CTX and EVP_CIPHER_CTX->cipher are not null 3. Add the start of reusable safety macros inspired by [s2n-tls](https://github.com/aws/s2n-tls/blob/main/docs/SAFETY-MACROS.md) ### Call-outs: This is an alternative approach to #1420. The `__AWS_LC_ENSURE` macro uses the `do {} while (0)` trick to ensure the action is run once, anything passed into the macro doesn't accidentally expand and change the scope, and the compiler enforces you add a `;` after the macro. We use this trick in other macros and all compilers are smart enough to optimize out the jump. ### Testing: `GUARD_PTR(ctx);` expands to: ``` do { if (!((ctx) != ((void *)0))) { ERR_put_error(ERR_LIB_CRYPTO, 0, (3 | 64), "_file_name_", 259); return 0; } } while (0); ``` [Here is an example](https://godbolt.org/z/z99roroKq) with the macro, and here it is implemented as a [traditional if/else](https://godbolt.org/z/E56EYnnW9). Both result in the same code. 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
Showing
3 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters