From 36c8eae890dc81f0e25ebf0be1c6a969ffd9543a Mon Sep 17 00:00:00 2001 From: vegaMato Date: Tue, 18 Dec 2018 18:37:22 +0100 Subject: [PATCH] Remove usage of function chmod(2) to use fchmod(2) Race condition possibility; CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') Thanks to PA193 project https://github.com/vegaMato/PCSC-lite-project-tasks --- src/pcscdaemon.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pcscdaemon.c b/src/pcscdaemon.c index 6df360f5..2b28b174 100644 --- a/src/pcscdaemon.c +++ b/src/pcscdaemon.c @@ -685,12 +685,13 @@ int main(int argc, char **argv) "writing " PCSCLITE_RUN_PID " failed: %s", strerror(errno)); } - (void)close(f); /* set mode so that the file is world readable even is umask is * restrictive * The file is used by libpcsclite */ - (void)chmod(PCSCLITE_RUN_PID, mode); + (void)fchmod(f, mode); + + (void)close(f); } else Log2(PCSC_LOG_CRITICAL, "cannot create " PCSCLITE_RUN_PID ": %s",