Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 821fbd6

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 7525e4c commit 821fbd6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -1465,10 +1465,11 @@ SSLerrmessage(unsigned long ecode)
14651465
return errreason;
14661466

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

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

+6-5
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)