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

Fix evp_keyex_create error handling #487

Closed
wants to merge 1 commit into from
Closed

Conversation

deweerdt
Copy link
Member

No description provided.

@@ -656,8 +656,10 @@ static int evp_keyex_create(ptls_key_exchange_algorithm_t *algo, ptls_key_exchan
}

/* setup */
if ((ret = evp_keyex_init(algo, ctx, pkey)) != 0)
if ((ret = evp_keyex_init(algo, ctx, pkey)) != 0) {
pkey = NULL; /* was free'd in the error path */
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the PR.

IIUC, the rationale for this change is that if evp_keyex_init fails, refcount of pkey is decremented by evp_keyex_init, hence we should set pkey to NULL to avoid another decrement.

Assuming that is the case, I wonder if we should stop decrementing inside evp_keyex_init rather than adjusting here. Rationale is as follows.

In the other call site of evp_keyex_init which is ptls_openssl_create_key_exchange, when we return an error and the input key type is EVP_PKEY_EC or something unknown, refcount of pkey stays as is. It is only when the key type is X25519 that we decrement when returning an error, due to how evp_pkey_init is implemented today.

This sounds like a bug of evp_pkey_init. Hence the idea of not decrementing inside evp_pkey_init.

WDYT?

@kazuho
Copy link
Member

kazuho commented Oct 17, 2023

The other issue with this PR is that it is a partial fix; it does not deal with the case where malloc fails inside evp_keyex_init.

I've created #490, PTAL.

@kazuho kazuho closed this Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants