Skip to content

Commit 1e666fd

Browse files
committed
libpq: Use strerror_r instead of strerror
Commit 453c468 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 453c468, 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
1 parent da4017a commit 1e666fd

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,10 +1466,11 @@ SSLerrmessage(unsigned long ecode)
14661466
return errreason;
14671467

14681468
/*
1469-
* In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
1470-
* map system errno values. We can cover that shortcoming with this bit
1471-
* of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
1472-
* but that's okay because they don't have the shortcoming either.
1469+
* In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
1470+
* errno values anymore. (See OpenSSL source code for the explanation.)
1471+
* We can cover that shortcoming with this bit of code. Older OpenSSL
1472+
* versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
1473+
* they don't have the shortcoming either.
14731474
*/
14741475
#ifdef ERR_SYSTEM_ERROR
14751476
if (ERR_SYSTEM_ERROR(ecode))

src/interfaces/libpq/fe-secure-openssl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,15 +1759,16 @@ SSLerrmessage(unsigned long ecode)
17591759
#endif
17601760

17611761
/*
1762-
* In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
1763-
* map system errno values. We can cover that shortcoming with this bit
1764-
* of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
1765-
* but that's okay because they don't have the shortcoming either.
1762+
* In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
1763+
* errno values anymore. (See OpenSSL source code for the explanation.)
1764+
* We can cover that shortcoming with this bit of code. Older OpenSSL
1765+
* versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
1766+
* they don't have the shortcoming either.
17661767
*/
17671768
#ifdef ERR_SYSTEM_ERROR
17681769
if (ERR_SYSTEM_ERROR(ecode))
17691770
{
1770-
strlcpy(errbuf, strerror(ERR_GET_REASON(ecode)), SSL_ERR_LEN);
1771+
strerror_r(ERR_GET_REASON(ecode), errbuf, SSL_ERR_LEN);
17711772
return errbuf;
17721773
}
17731774
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy