Global: never leak fd to child processes

This commit is contained in:
李通洲
2023-12-04 15:14:40 +08:00
parent 82581aa9e4
commit 3fda6e425a
4 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -27,7 +27,7 @@ static void createSubfolders(const char* fileName)
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
{
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC;
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC;
int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
int FF_AUTO_CLOSE_FD fd = open(fileName, openFlagsModes, openFlagsRights);
@@ -87,7 +87,7 @@ bool ffAppendFDBuffer(int fd, FFstrbuf* buffer)
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
{
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY);
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY | O_CLOEXEC);
if(fd == -1)
return -1;
@@ -96,7 +96,7 @@ ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
{
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY);
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY | O_CLOEXEC);
if(fd == -1)
return false;
@@ -199,7 +199,7 @@ bool ffSuppressIO(bool suppress)
origOut = dup(STDOUT_FILENO);
origErr = dup(STDERR_FILENO);
nullFile = open("/dev/null", O_WRONLY);
nullFile = open("/dev/null", O_WRONLY | O_CLOEXEC);
init = true;
}
+2 -2
View File
@@ -20,9 +20,9 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r
if(units == 0)
return NULL;
FF_AUTO_CLOSE_FD int acpifd = open("/dev/acpi", O_RDONLY);
FF_AUTO_CLOSE_FD int acpifd = open("/dev/acpi", O_RDONLY | O_CLOEXEC);
if(acpifd < 0)
return "open(\"/dev/acpi\", O_RDONLY) failed";
return "open(\"/dev/acpi\", O_RDONLY | O_CLOEXEC) failed";
for(int i = 0; i < units; ++i)
{
+1 -1
View File
@@ -18,7 +18,7 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
{
path[sizeof(path) - 2] = i;
FF_AUTO_CLOSE_FD int blfd = open(path, O_RDONLY);
FF_AUTO_CLOSE_FD int blfd = open(path, O_RDONLY | O_CLOEXEC);
if (blfd < 0)
continue;
+1 -1
View File
@@ -620,7 +620,7 @@ static int getCacheFD(FFLogoRequestData* requestData, const char* fileName)
{
uint32_t cacheDirLength = requestData->cacheDir.length;
ffStrbufAppendS(&requestData->cacheDir, fileName);
int fd = open(requestData->cacheDir.chars, O_RDONLY);
int fd = open(requestData->cacheDir.chars, O_RDONLY | O_CLOEXEC);
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
return fd;
}