@cryptotaxi247 / netdata-1 / commits / 3d60322ad

Address NULL access (windows.plugin) (#21112)

address_null: Change NULL to valid address trying to avoid reported issue

thiagoftsm committed Oct 8, 2025 at 07:58 UTC 3d60322ada82cfd42af588b3a7986e514bdce6f1
1 file changed +8 -6
src/collectors/windows.plugin/perflib-storage.c
+8 -6
@@ -175,7 +175,8 @@ static STRING *getFileSystemType(struct logical_disk *d, const char *diskName)
175 return NULL;
176
177 char fileSystemNameBuffer[128] = {0}; // Buffer for file system name
178 - char pathBuffer[256] = {0}; // Path buffer to accommodate different formats
178 + char pathBuffer[260] = {0}; // Path buffer to accommodate different formats
179 + char volumeName[260] = {0};
180 DWORD serialNumber = 0;
181 DWORD maxComponentLength = 0;
182 DWORD fileSystemFlags = 0;
@@ -183,18 +184,18 @@ static STRING *getFileSystemType(struct logical_disk *d, const char *diskName)
184
185 // Check if the input is likely a drive letter (e.g., "C:")
186 if (isalpha((uint8_t)diskName[0]) && diskName[1] == ':' && diskName[2] == '\0')
186 - snprintf(pathBuffer, sizeof(pathBuffer), "%s\\", diskName); // Format as "C:\"
187 + snprintfz(pathBuffer, sizeof(pathBuffer) - 1, "%s\\", diskName); // Format as "C:\"
188 else
189 // Assume it's a Volume GUID path or a device path
189 - snprintf(pathBuffer, sizeof(pathBuffer), "\\\\.\\%s\\", diskName); // Format as "\\.\HarddiskVolume1\"
190 + snprintfz(pathBuffer, sizeof(pathBuffer) - 1, "\\\\.\\%s\\", diskName); // Format as "\\.\HarddiskVolume1\"
191
192 d->DriveType = GetDriveTypeA(pathBuffer);
193
194 // Attempt to get the volume information
195 success = GetVolumeInformationA(
196 pathBuffer, // Path to the disk
196 - NULL, // We don't need the volume name
197 - 0, // Size of volume name buffer is 0
197 + volumeName, // Volume name buffer
198 + 259, // Size of volume name bufferr
199 &serialNumber, // Volume serial number
200 &maxComponentLength, // Maximum component length
201 &fileSystemFlags, // File system flags
@@ -246,6 +247,7 @@ static inline void netdata_set_hd_usage(PERF_DATA_BLOCK *pDataBlock,
247 {
248 ULARGE_INTEGER totalNumberOfBytes;
249 ULARGE_INTEGER totalNumberOfFreeBytes;
250 + ULARGE_INTEGER totalAvailableToCaller;
251
252 // https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
253 #define MAX_DRIVE_LENGTH 255
@@ -256,7 +258,7 @@ static inline void netdata_set_hd_usage(PERF_DATA_BLOCK *pDataBlock,
258 // https://devblogs.microsoft.com/oldnewthing/20071101-00/?p=24613
259 // We are using the variable that should not be affected by qyota ()
260 if ((GetDriveTypeA(path) == DRIVE_UNKNOWN) || !GetDiskFreeSpaceExA(path,
259 - NULL,
261 + &totalAvailableToCaller,
262 &totalNumberOfBytes,
263 &totalNumberOfFreeBytes)) {
264 perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->percentDiskFree);