Packages (Windows): fixes possible UB

Reported by Github Copilot
This commit is contained in:
李通洲
2025-12-18 14:21:55 +08:00
parent 610fc2ea36
commit 288d25e17c
+5 -1
View File
@@ -20,6 +20,8 @@ static uint32_t getNumElements(const char* searchPath, DWORD type, const wchar_t
uint8_t buffer[64 * 1024] __attribute__((aligned(8))); // Required for WoA
BOOLEAN firstScan = TRUE;
size_t ignoreLen = ignore ? wcslen(ignore) : 0;
while (true) {
IO_STATUS_BLOCK ioStatus = {};
NTSTATUS status = NtQueryDirectoryFile(
@@ -42,7 +44,9 @@ static uint32_t getNumElements(const char* searchPath, DWORD type, const wchar_t
{
if (!(entry->FileAttributes & type)) continue;
if (!flag && _wcsicmp(entry->FileName, ignore) == 0)
if (!flag &&
ignoreLen == entry->FileNameLength / sizeof(*entry->FileName) &&
_wcsnicmp(entry->FileName, ignore, ignoreLen) == 0)
{
flag = true;
continue;