From d7a150e79bc16a8486cc26bcb229e719425e057f Mon Sep 17 00:00:00 2001 From: Samuel Coleman Date: Mon, 3 May 2021 20:52:29 +0100 Subject: [PATCH] Fix FD leak when checking lock dir permissions. `mkstemp(3)` creates and opens a file descriptor for a temporary file, but this file descriptor was immediately discarded in favour of `fopen(3)`'ing the file by name and using that `FILE *` stream. I'm sure whoever originally wrote this code meant to use `mktemp(3)` instead, which only creates a unique file from a template name (equivalent to `mktemp(1)`). --- src/main/c/src/SerialImp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/src/SerialImp.c b/src/main/c/src/SerialImp.c index 16d7b0e0..59c6ab32 100644 --- a/src/main/c/src/SerialImp.c +++ b/src/main/c/src/SerialImp.c @@ -5830,7 +5830,7 @@ int check_group_uucp() strcat(testLockAbsFileName, testLockFileDirName); strcat(testLockAbsFileName, "/"); strcat(testLockAbsFileName, testLockFileName); - if ( 0 == mkstemp(testLockAbsFileName) ) + if ( 0 == strlen(mktemp(testLockAbsFileName)) ) { free(testLockAbsFileName); report_error("check_group_uucp(): mktemp malformed string - \