From 70160d324fe92b5ae97f97fa43d14199a26b646b Mon Sep 17 00:00:00 2001 From: apocelipes Date: Mon, 18 Dec 2023 17:04:26 +0900 Subject: [PATCH] fix(DiskIO, PhysicalDisk): fix readlink --- src/detection/diskio/diskio_linux.c | 7 +++++-- src/detection/physicaldisk/physicaldisk_linux.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/detection/diskio/diskio_linux.c b/src/detection/diskio/diskio_linux.c index fc9ffe043..e865581c2 100644 --- a/src/detection/diskio/diskio_linux.c +++ b/src/detection/diskio/diskio_linux.c @@ -23,8 +23,11 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) char pathSysBlock[PATH_MAX]; snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s", devName); - char pathSysDeviceReal[PATH_MAX] = ""; - readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1); + char pathSysDeviceReal[PATH_MAX]; + ssize_t pathLength = readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1); + if (pathLength < 0) + continue; + pathSysDeviceReal[pathLength] = '\0'; if (strstr(pathSysDeviceReal, "/virtual/")) // virtual device continue; diff --git a/src/detection/physicaldisk/physicaldisk_linux.c b/src/detection/physicaldisk/physicaldisk_linux.c index ac4311e5a..b94667731 100644 --- a/src/detection/physicaldisk/physicaldisk_linux.c +++ b/src/detection/physicaldisk/physicaldisk_linux.c @@ -23,8 +23,11 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) char pathSysBlock[PATH_MAX]; snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s", devName); - char pathSysDeviceReal[PATH_MAX] = ""; - readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1); + char pathSysDeviceReal[PATH_MAX]; + ssize_t pathLength = readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1); + if (pathLength < 0) + continue; + pathSysDeviceReal[pathLength] = '\0'; if (strstr(pathSysDeviceReal, "/virtual/")) // virtual device continue;