mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Improve error handling in backend OpenSSL implementation
Commit d94c36a45ab introduced error handling to sslinfo to handle OpenSSL errors gracefully. This ports this errorhandling to the backend TLS implementation. Author: Daniel Gustafsson <daniel@yesql.se>
This commit is contained in:
parent
5d1833f414
commit
13cfa02f77
@ -1298,15 +1298,28 @@ X509_NAME_to_cstring(X509_NAME *name)
|
|||||||
char *dp;
|
char *dp;
|
||||||
char *result;
|
char *result;
|
||||||
|
|
||||||
|
if (membuf == NULL)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||||
|
errmsg("failed to create BIO")));
|
||||||
|
|
||||||
(void) BIO_set_close(membuf, BIO_CLOSE);
|
(void) BIO_set_close(membuf, BIO_CLOSE);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
e = X509_NAME_get_entry(name, i);
|
e = X509_NAME_get_entry(name, i);
|
||||||
nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(e));
|
nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(e));
|
||||||
|
if (nid == NID_undef)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
|
errmsg("could not get NID for ASN1_OBJECT object")));
|
||||||
v = X509_NAME_ENTRY_get_data(e);
|
v = X509_NAME_ENTRY_get_data(e);
|
||||||
field_name = OBJ_nid2sn(nid);
|
field_name = OBJ_nid2sn(nid);
|
||||||
if (!field_name)
|
if (field_name == NULL)
|
||||||
field_name = OBJ_nid2ln(nid);
|
field_name = OBJ_nid2ln(nid);
|
||||||
|
if (field_name == NULL)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||||
|
errmsg("could not convert NID %d to an ASN1_OBJECT structure", nid)));
|
||||||
BIO_printf(membuf, "/%s=", field_name);
|
BIO_printf(membuf, "/%s=", field_name);
|
||||||
ASN1_STRING_print_ex(membuf, v,
|
ASN1_STRING_print_ex(membuf, v,
|
||||||
((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
|
((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
|
||||||
@ -1322,7 +1335,8 @@ X509_NAME_to_cstring(X509_NAME *name)
|
|||||||
result = pstrdup(dp);
|
result = pstrdup(dp);
|
||||||
if (dp != sp)
|
if (dp != sp)
|
||||||
pfree(dp);
|
pfree(dp);
|
||||||
BIO_free(membuf);
|
if (BIO_free(membuf) != 1)
|
||||||
|
elog(ERROR, "could not free OpenSSL BIO structure");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user