From 5d48efff83b6fdae4767f16014f8391a22d31ac9 Mon Sep 17 00:00:00 2001 From: Dag-Erling Smørgrav Date: Thu, 19 Nov 2020 05:44:41 +0000 Subject: Merge upstream r948: fix race condition in openpam_ttyconv(3). --- CREDITS | 1 + lib/libpam/openpam_ttyconv.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CREDITS b/CREDITS index b40c9d3b4826f..a560f9e12c1ff 100644 --- a/CREDITS +++ b/CREDITS @@ -18,6 +18,7 @@ ideas: Ankita Pal Baptiste Daroussin Brian Fundakowski Feldman + Brooks Davis Christos Zoulas Daniel Richard G. Darren J. Moffat diff --git a/lib/libpam/openpam_ttyconv.c b/lib/libpam/openpam_ttyconv.c index 8066b3b672986..1a50f1c99639f 100644 --- a/lib/libpam/openpam_ttyconv.c +++ b/lib/libpam/openpam_ttyconv.c @@ -94,12 +94,6 @@ prompt_tty(int ifd, int ofd, const char *message, char *response, int echo) int pos, ret; char ch; - /* write prompt */ - if (write(ofd, message, strlen(message)) < 0) { - openpam_log(PAM_LOG_ERROR, "write(): %m"); - return (-1); - } - /* turn echo off if requested */ slflag = 0; /* prevent bogus uninitialized variable warning */ if (!echo) { @@ -115,6 +109,12 @@ prompt_tty(int ifd, int ofd, const char *message, char *response, int echo) } } + /* write prompt */ + if (write(ofd, message, strlen(message)) < 0) { + openpam_log(PAM_LOG_ERROR, "write(): %m"); + return (-1); + } + /* install signal handlers */ caught_signal = 0; action.sa_handler = &catch_signal; -- cgit v1.3