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

Change sk_*_find signature to 2-arg for OpenSSL comapat #1429

Merged
merged 6 commits into from
Feb 15, 2024

Conversation

WillChilds-Klein
Copy link
Contributor

@WillChilds-Klein WillChilds-Klein commented Feb 1, 2024

Description of changes:

OpenSSL omits the |out_index| parameter from |sk_*_find|. This (breaking) change conforms with that interface and exposes our old, 3-arg interface with |out_index| as |sk_*_find_awslc|.

Call-outs:

  • This is a breaking change for consumers using the |sk_*_find| function. Consuming code will need to be updated to either use the new |sk_*_find| function or to drop the second positional |out_index| parameter from their function call(s).

Testing:

  • CI checks

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.

@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (5c35810) 76.88% compared to head (cf4cc69) 76.83%.

Files Patch % Lines
crypto/x509/by_dir.c 0.00% 3 Missing ⚠️
crypto/x509/policy.c 75.00% 1 Missing ⚠️
crypto/x509/x509_trs.c 0.00% 1 Missing ⚠️
crypto/x509v3/v3_lib.c 0.00% 1 Missing ⚠️
crypto/x509v3/v3_purp.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1429      +/-   ##
==========================================
- Coverage   76.88%   76.83%   -0.06%     
==========================================
  Files         425      425              
  Lines       71527    71526       -1     
==========================================
- Hits        54991    54954      -37     
- Misses      16536    16572      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@WillChilds-Klein WillChilds-Klein marked this pull request as ready for review February 1, 2024 17:52
@WillChilds-Klein WillChilds-Klein requested a review from a team as a code owner February 1, 2024 17:52
@WillChilds-Klein WillChilds-Klein marked this pull request as draft February 1, 2024 18:38
include/openssl/stack.h Outdated Show resolved Hide resolved
@WillChilds-Klein WillChilds-Klein force-pushed the sk_find branch 4 times, most recently from c4e5e31 to 5f1e186 Compare February 5, 2024 18:59
@WillChilds-Klein WillChilds-Klein marked this pull request as ready for review February 5, 2024 19:28
/* use 2-arg sk_*_find for OpenSSL compatibility */ \
OPENSSL_INLINE int sk_##name##_find(const STACK_OF(name) *sk, \
constptrtype p) { \
const size_t mask = sizeof(size_t) > sizeof(int) \
Copy link
Contributor

@justsmth justsmth Feb 5, 2024

Choose a reason for hiding this comment

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

The mask should also cover the sign bit, even if sizeof(size_t) == sizeof(int):

const size_t mask = (~((size_t) 0)) << (sizeof(int) * 8 - 1);

I don't think it's the case for any supported platform that
sizeof(size_t) < sizeof(int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mask should also cover the sign bit, even if sizeof(size_t) == sizeof(int)

size_t is always unsigned, no?

I don't think it's the case for any supported platform that sizeof(size_t) < sizeof(int)

I didn't think so either, but am concerned with the sizeof(size_t) == sizeof(int) case, hence the hard inequality. Initially I'd written this as sizeof(size_t) != sizeof(int), used < to guard against cases I hadn't considered.

In any case, something is wrong with my implementation here. The ubuntu1604_gcc5x_x86 test is failing with a compile error:

../include/openssl/stack.h:509:46: error: left shift count >= width of type [-Werror=shift-count-overflow]
         ? (~((size_t) 0)) << (sizeof(int) * 8)                                 \
                                              ^

Same with centos7_gcc4x_x86_64_fips. I'll look into how earlier versions of GCC handle bit shifting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up dropping the masking logic altogether in favor of checking INT_MAX and casting.

Comment on lines +511 to +512
int ok = OPENSSL_sk_find((const OPENSSL_STACK *)sk, &out_index, \
(const void *)p, sk_##name##_call_cmp_func); \
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can this call sk_##name##_find_awslc? No strong preference though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would work, but IMO we should put any checks, etc. we want shared by both sk_*_find and sk_*_find_awslc in the concrete function OPENSSL_sk_find rather than one of the wrapping macros.

@WillChilds-Klein WillChilds-Klein merged commit 9860446 into aws:main Feb 15, 2024
38 checks passed
@WillChilds-Klein WillChilds-Klein deleted the sk_find branch February 15, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants