summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-07-28 09:12:00 +0200
committerPeter Eisentraut <peter@eisentraut.org>2024-07-28 09:25:03 +0200
commitc53016860b8e9c7d511efa86d6368456340343f5 (patch)
treef5d6e6fb22088ca136e71b741cea17e1c26e8daa /src
parent1091f8e0a48bf934e73260501799ce49405c67cf (diff)
libpq: Use strerror_r instead of strerror
Commit 453c4687377 introduced a use of strerror() into libpq, but that is not thread-safe. Fix by using strerror_r() instead. In passing, update some of the code comments added by 453c4687377, as we have learned more about the reason for the change in OpenSSL that started this. Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: Discussion: https://postgr.es/m/b6fb018b-f05c-4afd-abd3-318c649faf18@highgo.ca
Diffstat (limited to 'src')
-rw-r--r--src/backend/libpq/be-secure-openssl.c9
-rw-r--r--src/interfaces/libpq/fe-secure-openssl.c11
2 files changed, 11 insertions, 9 deletions
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 6e53a15cbde..4e07ad8cd19 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -1379,10 +1379,11 @@ SSLerrmessage(unsigned long ecode)
return errreason;
/*
- * In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
- * map system errno values. We can cover that shortcoming with this bit
- * of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
- * but that's okay because they don't have the shortcoming either.
+ * In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
+ * errno values anymore. (See OpenSSL source code for the explanation.)
+ * We can cover that shortcoming with this bit of code. Older OpenSSL
+ * versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
+ * they don't have the shortcoming either.
*/
#ifdef ERR_SYSTEM_ERROR
if (ERR_SYSTEM_ERROR(ecode))
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index a44d7d3f29e..ee518d5b875 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -1707,15 +1707,16 @@ SSLerrmessage(unsigned long ecode)
}
/*
- * In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
- * map system errno values. We can cover that shortcoming with this bit
- * of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
- * but that's okay because they don't have the shortcoming either.
+ * In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
+ * errno values anymore. (See OpenSSL source code for the explanation.)
+ * We can cover that shortcoming with this bit of code. Older OpenSSL
+ * versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
+ * they don't have the shortcoming either.
*/
#ifdef ERR_SYSTEM_ERROR
if (ERR_SYSTEM_ERROR(ecode))
{
- strlcpy(errbuf, strerror(ERR_GET_REASON(ecode)), SSL_ERR_LEN);
+ strerror_r(ERR_GET_REASON(ecode), errbuf, SSL_ERR_LEN);
return errbuf;
}
#endif