mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
Ensure X509_STORE_CTX_purpose_inherit handles a 0 default purpose
The function X509_STORE_CTX_purpose_inherit() can be called with a 0 default purpose. If the main purpose was set to X509_PURPOSE_ANY this would case the function to incorrectly return an error response. Fixes #17367 Reviewed-by: Ben Kaduk <kaduk@mit.edu> (Merged from https://github.com/openssl/openssl/pull/17382)
This commit is contained in:
parent
2ce0a3d190
commit
4aa8285026
@ -2230,6 +2230,12 @@ int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
|
|||||||
/* If purpose not set use default */
|
/* If purpose not set use default */
|
||||||
if (purpose == 0)
|
if (purpose == 0)
|
||||||
purpose = def_purpose;
|
purpose = def_purpose;
|
||||||
|
/*
|
||||||
|
* If purpose is set but we don't have a default then set the default to
|
||||||
|
* the current purpose
|
||||||
|
*/
|
||||||
|
else if (def_purpose == 0)
|
||||||
|
def_purpose = purpose;
|
||||||
/* If we have a purpose then check it is valid */
|
/* If we have a purpose then check it is valid */
|
||||||
if (purpose != 0) {
|
if (purpose != 0) {
|
||||||
X509_PURPOSE *ptmp;
|
X509_PURPOSE *ptmp;
|
||||||
@ -2242,11 +2248,6 @@ int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
|
|||||||
ptmp = X509_PURPOSE_get0(idx);
|
ptmp = X509_PURPOSE_get0(idx);
|
||||||
if (ptmp->trust == X509_TRUST_DEFAULT) {
|
if (ptmp->trust == X509_TRUST_DEFAULT) {
|
||||||
idx = X509_PURPOSE_get_by_id(def_purpose);
|
idx = X509_PURPOSE_get_by_id(def_purpose);
|
||||||
/*
|
|
||||||
* XXX: In the two callers above def_purpose is always 0, which is
|
|
||||||
* not a known value, so idx will always be -1. How is the
|
|
||||||
* X509_TRUST_DEFAULT case actually supposed to be handled?
|
|
||||||
*/
|
|
||||||
if (idx == -1) {
|
if (idx == -1) {
|
||||||
ERR_raise(ERR_LIB_X509, X509_R_UNKNOWN_PURPOSE_ID);
|
ERR_raise(ERR_LIB_X509, X509_R_UNKNOWN_PURPOSE_ID);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user