Skip to content

Commit da5d7a7

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 634710d commit da5d7a7

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
@@ -1175,10 +1175,11 @@ SSLerrmessage(unsigned long ecode)
11751175
return errreason;
11761176

11771177
/*
1178-
* In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
1179-
* map system errno values. We can cover that shortcoming with this bit
1180-
* of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
1181-
* but that's okay because they don't have the shortcoming either.
1178+
* In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
1179+
* errno values anymore. (See OpenSSL source code for the explanation.)
1180+
* We can cover that shortcoming with this bit of code. Older OpenSSL
1181+
* versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
1182+
* they don't have the shortcoming either.
11821183
*/
11831184
#ifdef ERR_SYSTEM_ERROR
11841185
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
@@ -1498,15 +1498,16 @@ SSLerrmessage(unsigned long ecode)
14981498
}
14991499

15001500
/*
1501-
* In OpenSSL 3.0.0 and later, ERR_reason_error_string randomly refuses to
1502-
* map system errno values. We can cover that shortcoming with this bit
1503-
* of code. Older OpenSSL versions don't have the ERR_SYSTEM_ERROR macro,
1504-
* but that's okay because they don't have the shortcoming either.
1501+
* In OpenSSL 3.0.0 and later, ERR_reason_error_string does not map system
1502+
* errno values anymore. (See OpenSSL source code for the explanation.)
1503+
* We can cover that shortcoming with this bit of code. Older OpenSSL
1504+
* versions don't have the ERR_SYSTEM_ERROR macro, but that's okay because
1505+
* they don't have the shortcoming either.
15051506
*/
15061507
#ifdef ERR_SYSTEM_ERROR
15071508
if (ERR_SYSTEM_ERROR(ecode))
15081509
{
1509-
strlcpy(errbuf, strerror(ERR_GET_REASON(ecode)), SSL_ERR_LEN);
1510+
strerror_r(ERR_GET_REASON(ecode), errbuf, SSL_ERR_LEN);
15101511
return errbuf;
15111512
}
15121513
#endif

0 commit comments

Comments
 (0)