summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-18 08:08:30 +0200
committerGitHub <noreply@github.com>2021-05-18 08:08:30 +0200
commit3ef6e31ded51964502e2702ace6443a42fef0eca (patch)
treeb780552e5544a00c6e677af4147dc70c11323c43 /Userland/Libraries
parent812875bc89cfe380e2d9dc7ff75803a36b0810fa (diff)
downloadserenity-3ef6e31ded51964502e2702ace6443a42fef0eca.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibC/pty.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/Userland/Libraries/LibC/pty.cpp b/Userland/Libraries/LibC/pty.cpp
index b2ad1e10ba..19706951a6 100644
--- a/Userland/Libraries/LibC/pty.cpp
+++ b/Userland/Libraries/LibC/pty.cpp
@@ -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;