LibC: Use ptsname_r() instead of ptsname() in openpty() (#7231)

This improves thread-safety because ptsname() is using a global
buffer that is shared between threads.
This commit is contained in:
Gunnar Beutner 2021-05-18 08:08:30 +02:00 committed by GitHub
parent 812875bc89
commit 3ef6e31ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: sideshowbarker 2024-07-18 17:53:19 +09:00

View File

@ -34,8 +34,9 @@ int openpty(int* amaster, int* aslave, char* name, const struct termios* termp,
return -1;
}
const char* tty_name = ptsname(*amaster);
if (!tty_name) {
char tty_name[32];
int rc = ptsname_r(*amaster, tty_name, sizeof(tty_name));
if (rc < 0) {
int error = errno;
close(*amaster);
errno = error;