From 88a8c1ce937b2cd068da0c1828b4d87a75b49c7c Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 11 Feb 2024 21:33:04 +0900 Subject: [PATCH] plugins/micron: Fix code scanning alert Fix the time-of-check time-of-use filesystem race condition. Signed-off-by: Tokunori Ikegami --- plugins/micron/micron-nvme.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/micron/micron-nvme.c b/plugins/micron/micron-nvme.c index 63a7a7950e..f35fd2defc 100644 --- a/plugins/micron/micron-nvme.c +++ b/plugins/micron/micron-nvme.c @@ -319,7 +319,8 @@ static int SetupDebugDataDirectories(char *strSN, char *strFilePath, if (strOSDirName) { sprintf(strOSDirName, "%s/%s", strMainDirName, "OS"); if (mkdir(strOSDirName, 0777) < 0) { - rmdir(strMainDirName); + if (access(strMainDirName, F_OK)) + rmdir(strMainDirName); err = -1; goto exit_status; } @@ -329,9 +330,10 @@ static int SetupDebugDataDirectories(char *strSN, char *strFilePath, if (mkdir(strCtrlDirName, 0777) < 0) { if (strOSDirName) rmdir(strOSDirName); - rmdir(strMainDirName); + if (access(strMainDirName, F_OK)) + rmdir(strMainDirName); err = -1; - } + } } exit_status: