Skip to content

Commit 3d462f0

Browse files
committed
Fix error handling around ssl_*_protocol_version settings
In case of a reload, we just want to LOG errors instead of FATAL when processing SSL configuration, but the more recent code for the ssl_*_protocol_version settings didn't behave like that. Author: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Michael Paquier <michael@paquier.xyz>
1 parent 08d25d7 commit 3d462f0

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/backend/libpq/be-secure-openssl.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ static bool SSL_initialized = false;
6767
static bool dummy_ssl_passwd_cb_called = false;
6868
static bool ssl_is_server_start;
6969

70-
static int ssl_protocol_version_to_openssl(int v, const char *guc_name);
70+
static int ssl_protocol_version_to_openssl(int v, const char *guc_name,
71+
int loglevel);
7172
#ifndef SSL_CTX_set_min_proto_version
7273
static int SSL_CTX_set_min_proto_version(SSL_CTX *ctx, int version);
7374
static int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, int version);
@@ -190,13 +191,24 @@ be_tls_init(bool isServerStart)
190191
}
191192

192193
if (ssl_min_protocol_version)
193-
SSL_CTX_set_min_proto_version(context,
194-
ssl_protocol_version_to_openssl(ssl_min_protocol_version,
195-
"ssl_min_protocol_version"));
194+
{
195+
int ssl_ver = ssl_protocol_version_to_openssl(ssl_min_protocol_version,
196+
"ssl_min_protocol_version",
197+
isServerStart ? FATAL : LOG);
198+
if (ssl_ver == -1)
199+
goto error;
200+
SSL_CTX_set_min_proto_version(context, ssl_ver);
201+
}
202+
196203
if (ssl_max_protocol_version)
197-
SSL_CTX_set_max_proto_version(context,
198-
ssl_protocol_version_to_openssl(ssl_max_protocol_version,
199-
"ssl_max_protocol_version"));
204+
{
205+
int ssl_ver = ssl_protocol_version_to_openssl(ssl_max_protocol_version,
206+
"ssl_max_protocol_version",
207+
isServerStart ? FATAL : LOG);
208+
if (ssl_ver == -1)
209+
goto error;
210+
SSL_CTX_set_max_proto_version(context, ssl_ver);
211+
}
200212

201213
/* disallow SSL session tickets */
202214
#ifdef SSL_OP_NO_TICKET /* added in OpenSSL 0.9.8f */
@@ -1258,11 +1270,12 @@ X509_NAME_to_cstring(X509_NAME *name)
12581270
* guc.c independent of OpenSSL availability and version.
12591271
*
12601272
* If a version is passed that is not supported by the current OpenSSL
1261-
* version, then we throw an error, so that subsequent code can assume it's
1262-
* working with a supported version.
1273+
* version, then we log with the given loglevel and return (if we return) -1.
1274+
* If a nonnegative value is returned, subsequent code can assume it's working
1275+
* with a supported version.
12631276
*/
12641277
static int
1265-
ssl_protocol_version_to_openssl(int v, const char *guc_name)
1278+
ssl_protocol_version_to_openssl(int v, const char *guc_name, int loglevel)
12661279
{
12671280
switch (v)
12681281
{
@@ -1292,7 +1305,7 @@ ssl_protocol_version_to_openssl(int v, const char *guc_name)
12921305

12931306
error:
12941307
pg_attribute_unused();
1295-
ereport(ERROR,
1308+
ereport(loglevel,
12961309
(errmsg("%s setting %s not supported by this build",
12971310
guc_name,
12981311
GetConfigOption(guc_name, false, false))));

0 commit comments

Comments
 (0)