Skip to content

Commit

Permalink
fix(DiskIO, PhysicalDisk): fix readlink
Browse files Browse the repository at this point in the history
  • Loading branch information
apocelipes authored and CarterLi committed Dec 18, 2023
1 parent 600f6c7 commit 70160d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/detection/diskio/diskio_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/detection/physicaldisk/physicaldisk_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 70160d3

Please sign in to comment.