Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce that ENSURE and GUARD_OSSL use valid error codes #3873

Merged
merged 3 commits into from
Mar 11, 2023

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Mar 10, 2023

Description of changes:

I noticed that the same mistake made in #3853 (comment) has been made in several other places in the codebase. I corrected them all and added a check to grep_simple_mistakes.

To make the check work, I also had to correct S2N_RSA_PSS_NOT_SUPPORTED to S2N_ERR_RSA_PSS_NOT_SUPPORTED.

Testing:

This is the result if I intentionally re-introduce mistakes:

ENSURE and GUARD_OSSL require a valid error code from errors/s2n_errno.h:
/home/lrstewart/Code/s2n-tls/pq-crypto/s2n_kyber_512_evp.c:    POSIX_GUARD_OSSL(EVP_PKEY_keygen_init(kyber_pkey_ctx), S2N_FAILURE);
/home/lrstewart/Code/s2n-tls/utils/s2n_mem.c:    POSIX_ENSURE(sysconf_rc > 0, S2N_FAILURE);

FAILED Grep For Simple Mistakes check

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Mar 10, 2023
@lrstewart lrstewart marked this pull request as ready for review March 10, 2023 23:51
@lrstewart lrstewart requested a review from dougch as a code owner March 10, 2023 23:51

/* page_size must be a valid uint32 */
POSIX_ENSURE(sysconf_rc <= UINT32_MAX, S2N_FAILURE);
POSIX_ENSURE_LTE(sysconf_rc, UINT32_MAX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why POSIX_ENSURE lets you specify the error code, but POSIX_ENSURE_LTE, etc always uses S2N_ERR_SAFETY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POSIX_ENSURE_LTE(x, y) is just a shorthand for POSIX_ENSURE(x <= y, S2N_ERR_SAFETY). If you want to specify an error other than S2N_ERR_SAFETY, you use POSIX_ENSURE.

@lrstewart lrstewart enabled auto-merge (squash) March 11, 2023 04:38
@lrstewart lrstewart merged commit 77d70d8 into aws:main Mar 11, 2023
@lrstewart lrstewart deleted the fix branch March 11, 2023 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants