Skip to content

Commit 288d25e

Browse files
committed
Packages (Windows): fixes possible UB
Reported by Github Copilot
1 parent 610fc2e commit 288d25e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/detection/packages/packages_windows.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static uint32_t getNumElements(const char* searchPath, DWORD type, const wchar_t
2020
uint8_t buffer[64 * 1024] __attribute__((aligned(8))); // Required for WoA
2121
BOOLEAN firstScan = TRUE;
2222

23+
size_t ignoreLen = ignore ? wcslen(ignore) : 0;
24+
2325
while (true) {
2426
IO_STATUS_BLOCK ioStatus = {};
2527
NTSTATUS status = NtQueryDirectoryFile(
@@ -42,7 +44,9 @@ static uint32_t getNumElements(const char* searchPath, DWORD type, const wchar_t
4244
{
4345
if (!(entry->FileAttributes & type)) continue;
4446

45-
if (!flag && _wcsicmp(entry->FileName, ignore) == 0)
47+
if (!flag &&
48+
ignoreLen == entry->FileNameLength / sizeof(*entry->FileName) &&
49+
_wcsnicmp(entry->FileName, ignore, ignoreLen) == 0)
4650
{
4751
flag = true;
4852
continue;

0 commit comments

Comments
 (0)