From 7f20bb88ad8ec78d64cb2d02f22165a697367d48 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 11 Dec 2023 17:18:38 +0100 Subject: [PATCH] lib/utmp: merge file access Avoid checking if the file exists before opening it. Resolves a CodeQL report of Time-of-check time-of-use filesystem race condition. --- lib/utmp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/utmp.c b/lib/utmp.c index dabe8b2e8..6acd196f0 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -85,15 +85,13 @@ static void failtmp (const char *username, const struct utmp *failent) * feature to be used. */ - if (access (ftmp, F_OK) != 0) { - return; - } - fd = open (ftmp, O_WRONLY | O_APPEND); if (-1 == fd) { - SYSLOG ((LOG_WARN, - "Can't append failure of user %s to %s.", - username, ftmp)); + if (errno != ENOENT) { + SYSLOG ((LOG_WARN, + "Can't append failure of user %s to %s: %m", + username, ftmp)); + } return; } -- 2.47.3