Skip to content

Commit 95e805e

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 ddd66a6 commit 95e805e

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
@@ -1254,10 +1254,11 @@ SSLerrmessage(unsigned long ecode)
12541254
return errreason;
12551255

12561256
/*
1257-
* In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
1258-
* map system errno values. We can cover that shortcoming with this bit
1259-
* of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
1260-
* but that's okay because they don't have the shortcoming either.
1257+
* In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
1258+
* errno values anymore. (See OpenSSL source code for the explanation.)
1259+
* We can cover that shortcoming with this bit of code. Older OpenSSL
1260+
* versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
1261+
* they don't have the shortcoming either.
12611262
*/
12621263
#ifdef ERR_SYSTEM_ERROR
12631264
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
@@ -1557,15 +1557,16 @@ SSLerrmessage(unsigned long ecode)
15571557
}
15581558

15591559
/*
1560-
* In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
1561-
* map system errno values. We can cover that shortcoming with this bit
1562-
* of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
1563-
* but that's okay because they don't have the shortcoming either.
1560+
* In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
1561+
* errno values anymore. (See OpenSSL source code for the explanation.)
1562+
* We can cover that shortcoming with this bit of code. Older OpenSSL
1563+
* versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
1564+
* they don't have the shortcoming either.
15641565
*/
15651566
#ifdef ERR_SYSTEM_ERROR
15661567
if (ERR_SYSTEM_ERROR(ecode))
15671568
{
1568-
strlcpy(errbuf, strerror(ERR_GET_REASON(ecode)), SSL_ERR_LEN);
1569+
strerror_r(ERR_GET_REASON(ecode), errbuf, SSL_ERR_LEN);
15691570
return errbuf;
15701571
}
15711572
#endif

0 commit comments

Comments
 (0)