Skip to content

Commit eec1814

Browse files
bhanunamikzebhanunamikze
authored andcommitted
fix: null function pointer crash in enumerate_dirs — root cause of silent BOF crashes
enumerate_dirs() called with NULL callback at triage.c:357, but never checked for NULL before calling callback(). When subdirectories existed under C:\Users\{user}\AppData\Roaming\Microsoft\Protect, this caused an immediate null pointer dereference crash. Fixes: - Add 'if (callback)' guard to all 4 callback call sites in enumerate_files() and enumerate_dirs() - Remove useless enumerate_dirs(mk_path, NULL, NULL) call
1 parent a472f49 commit eec1814

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/common/triage.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void enumerate_files(const wchar_t* dir, const wchar_t* pattern,
8383

8484
wchar_t full_path[MAX_PATH * 2];
8585
swprintf(full_path, L"%s\\%s", dir, ffd.cFileName);
86-
callback(full_path, ctx);
86+
if (callback) callback(full_path, ctx);
8787
} while (KERNEL32$FindNextFileW(hFind, &ffd));
8888
KERNEL32$FindClose(hFind);
8989
#else
@@ -96,7 +96,7 @@ static void enumerate_files(const wchar_t* dir, const wchar_t* pattern,
9696

9797
wchar_t full_path[MAX_PATH * 2];
9898
swprintf(full_path, L"%s\\%s", dir, ffd.cFileName);
99-
callback(full_path, ctx);
99+
if (callback) callback(full_path, ctx);
100100
} while (FindNextFileW(hFind, &ffd));
101101
FindClose(hFind);
102102
#endif
@@ -120,7 +120,7 @@ static void enumerate_dirs(const wchar_t* dir, FILE_CALLBACK callback, void* ctx
120120

121121
wchar_t full_path[MAX_PATH * 2];
122122
swprintf(full_path, L"%s\\%s", dir, ffd.cFileName);
123-
callback(full_path, ctx);
123+
if (callback) callback(full_path, ctx);
124124
} while (KERNEL32$FindNextFileW(hFind, &ffd));
125125
KERNEL32$FindClose(hFind);
126126
#else
@@ -133,7 +133,7 @@ static void enumerate_dirs(const wchar_t* dir, FILE_CALLBACK callback, void* ctx
133133

134134
wchar_t full_path[MAX_PATH * 2];
135135
swprintf(full_path, L"%s\\%s", dir, ffd.cFileName);
136-
callback(full_path, ctx);
136+
if (callback) callback(full_path, ctx);
137137
} while (FindNextFileW(hFind, &ffd));
138138
FindClose(hFind);
139139
#endif
@@ -353,9 +353,6 @@ BOOL triage_user_masterkeys(MASTERKEY_CACHE* cache,
353353
wchar_t mk_path[MAX_PATH * 2];
354354
swprintf(mk_path, L"%s\\AppData\\Roaming\\Microsoft\\Protect", users[i]);
355355

356-
/* Enumerate SID directories under Protect */
357-
enumerate_dirs(mk_path, (FILE_CALLBACK)NULL, NULL);
358-
359356
/* For each SID directory, triage masterkey files */
360357
WIN32_FIND_DATAW ffd;
361358
wchar_t search[MAX_PATH * 2];

0 commit comments

Comments
 (0)