Skip to content

Comments

Constify the X509_STORE_CTX argument to the lookup_certs functions.#29488

Closed
bob-beck wants to merge 1 commit intoopenssl:masterfrom
bob-beck:lookup-certs-const-ctx
Closed

Constify the X509_STORE_CTX argument to the lookup_certs functions.#29488
bob-beck wants to merge 1 commit intoopenssl:masterfrom
bob-beck:lookup-certs-const-ctx

Conversation

@bob-beck
Copy link
Contributor

@bob-beck bob-beck commented Dec 22, 2025

The justification for this not being const was because of lookup_certs_sk(). The reasons this function could not have a const store, is that it set the ctx's error code
when we could not allocate memory and returned NULL.

However, the other lookup_certs function, X509_STORE_CTX_get1_certs, already does not set this error code when failing to allocate memory on a return.

Given that you can't depend on the out of memory error code being set in the general case, and the Beyonce rule appears to indicate that nobody likes this behaviour (as nobody put a test on it) I think it's safe to say we should just not modify the ctx, and constify it.

beyonce-rule

For #28654

Checklist
  • documentation is added or updated
  • tests are added or updated

The justification for this not being const was because of
lookup_certs_sk(). The reasons this function could not have a
const store, is that it set the ctx's error code
when we could not allocate memory and returned NULL.

However, the other lookup_certs function, X509_STORE_CTX_get1_certs,
already does not set this error code when failing to allocate
memory on a return.

Given that you can't depend on the out of memory error code being
set in the general case, and the Beyonce rule appears to indicate
that nobody likes this behaviour (as nobody put a test on it) I
think it's safe to say we should just not modify the ctx, and
constify it.

For openssl#28654
@bob-beck bob-beck changed the title Constify the X509_STORE_CTX argument to the lookup_certs funcitons. Constify the X509_STORE_CTX argument to the lookup_certs functions. Dec 22, 2025
if (X509_NAME_cmp(nm, X509_get_subject_name(x)) == 0) {
if (!X509_add_cert(sk, x, X509_ADD_FLAG_UP_REF)) {
OSSL_STACK_OF_X509_free(sk);
ctx->error = X509_V_ERR_OUT_OF_MEM;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that X509_STORE_CTX_get1_certs returns NULL on failure to allocate without setting this error.

@bob-beck bob-beck marked this pull request as ready for review December 22, 2025 18:50
@github-actions github-actions bot added severity: fips change The pull request changes FIPS provider sources severity: ABI change This pull request contains ABI changes labels Dec 22, 2025
@FdaSilvaYY
Copy link
Contributor

Typo in commit message : funcitons

Copy link
Contributor

@jogme jogme left a comment

Choose a reason for hiding this comment

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

please typofix the commit msg as above, otherwise LGTM! Thanks!

@jogme jogme added approval: done This pull request has the required number of approvals branch: master Applies to master branch labels Jan 13, 2026
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jan 14, 2026
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Jan 19, 2026
The justification for this not being const was because of
lookup_certs_sk(). The reasons this function could not have a
const store, is that it set the ctx's error code
when we could not allocate memory and returned NULL.

However, the other lookup_certs function, X509_STORE_CTX_get1_certs,
already does not set this error code when failing to allocate
memory on a return.

Given that you can't depend on the out of memory error code being
set in the general case, and the Beyonce rule appears to indicate
that nobody likes this behaviour (as nobody put a test on it) I
think it's safe to say we should just not modify the ctx, and
constify it.

For #28654

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Norbert Pocs <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
MergeDate: Mon Jan 19 12:03:05 2026
(Merged from #29488)
@mattcaswell
Copy link
Member

Merged to master. Thank you for the contribution.

esyr pushed a commit to esyr/openssl that referenced this pull request Jan 19, 2026
The justification for this not being const was because of
lookup_certs_sk(). The reasons this function could not have a
const store, is that it set the ctx's error code
when we could not allocate memory and returned NULL.

However, the other lookup_certs function, X509_STORE_CTX_get1_certs,
already does not set this error code when failing to allocate
memory on a return.

Given that you can't depend on the out of memory error code being
set in the general case, and the Beyonce rule appears to indicate
that nobody likes this behaviour (as nobody put a test on it) I
think it's safe to say we should just not modify the ctx, and
constify it.

For openssl#28654

Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Norbert Pocs <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
MergeDate: Mon Jan 19 12:03:05 2026
(Merged from openssl#29488)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch severity: ABI change This pull request contains ABI changes severity: fips change The pull request changes FIPS provider sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants