Skip to content

Commit 1660eb1

Browse files
committed
Bug 1829382 - use binary search in mozglue blocklist r=handyman
Someday I would like to figure out why this blocklist only works on ASCII strings and the freestanding one works on wide strings, but I'll leave that for another time I guess. This gets us closer to unifying the logic between the two blocklists, which is nice. I ran the TestDllBlocklist* gtests locally while using the mozglue blocklist and the ones that are expected to pass do indeed pass. Differential Revision: https://phabricator.services.mozilla.com/D176444 UltraBlame original commit: 169ca1394b2747cb91f95fe618faebef3fb1663e
1 parent fb36821 commit 1660eb1

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -332,57 +332,57 @@ static wchar_t* lastslash(wchar_t* s, int len) {
332332
return nullptr;
333333
}
334334

335-
static bool ShouldBlockBasedOnBlockInfo(const DllBlockInfo* info,
335+
static bool ShouldBlockBasedOnBlockInfo(const DllBlockInfo& info,
336336
const char* dllName, PWCHAR filePath,
337337
wchar_t* fname,
338338
unsigned long long* fVersion) {
339339
#ifdef DEBUG_very_verbose
340340
printf_stderr("LdrLoadDll: info->mName: '%s'\n", info->mName);
341341
#endif
342342

343-
if (info->mFlags & DllBlockInfo::REDIRECT_TO_NOOP_ENTRYPOINT) {
343+
if (info.mFlags & DllBlockInfo::REDIRECT_TO_NOOP_ENTRYPOINT) {
344344
printf_stderr(
345345
"LdrLoadDll: "
346346
"Ignoring the REDIRECT_TO_NOOP_ENTRYPOINT flag\n");
347347
}
348348

349-
if ((info->mFlags & DllBlockInfo::BLOCK_WIN8_AND_OLDER) &&
349+
if ((info.mFlags & DllBlockInfo::BLOCK_WIN8_AND_OLDER) &&
350350
IsWin8Point1OrLater()) {
351351
return false;
352352
}
353353

354-
if ((info->mFlags & DllBlockInfo::BLOCK_WIN7_AND_OLDER) && IsWin8OrLater()) {
354+
if ((info.mFlags & DllBlockInfo::BLOCK_WIN7_AND_OLDER) && IsWin8OrLater()) {
355355
return false;
356356
}
357357

358-
if ((info->mFlags & DllBlockInfo::CHILD_PROCESSES_ONLY) &&
358+
if ((info.mFlags & DllBlockInfo::CHILD_PROCESSES_ONLY) &&
359359
!(sInitFlags & eDllBlocklistInitFlagIsChildProcess)) {
360360
return false;
361361
}
362362

363-
if ((info->mFlags & DllBlockInfo::UTILITY_PROCESSES_ONLY) &&
363+
if ((info.mFlags & DllBlockInfo::UTILITY_PROCESSES_ONLY) &&
364364
!(sInitFlags & eDllBlocklistInitFlagIsUtilityProcess)) {
365365
return false;
366366
}
367367

368-
if ((info->mFlags & DllBlockInfo::SOCKET_PROCESSES_ONLY) &&
368+
if ((info.mFlags & DllBlockInfo::SOCKET_PROCESSES_ONLY) &&
369369
!(sInitFlags & eDllBlocklistInitFlagIsSocketProcess)) {
370370
return false;
371371
}
372372

373-
if ((info->mFlags & DllBlockInfo::GPU_PROCESSES_ONLY) &&
373+
if ((info.mFlags & DllBlockInfo::GPU_PROCESSES_ONLY) &&
374374
!(sInitFlags & eDllBlocklistInitFlagIsGPUProcess)) {
375375
return false;
376376
}
377377

378-
if ((info->mFlags & DllBlockInfo::BROWSER_PROCESS_ONLY) &&
378+
if ((info.mFlags & DllBlockInfo::BROWSER_PROCESS_ONLY) &&
379379
(sInitFlags & eDllBlocklistInitFlagIsChildProcess)) {
380380
return false;
381381
}
382382

383383
*fVersion = DllBlockInfo::ALL_VERSIONS;
384384

385-
if (info->mMaxVersion != DllBlockInfo::ALL_VERSIONS) {
385+
if (info.mMaxVersion != DllBlockInfo::ALL_VERSIONS) {
386386
ReentrancySentinel sentinel(dllName);
387387
if (sentinel.BailOut()) {
388388
return false;
@@ -398,24 +398,35 @@ static bool ShouldBlockBasedOnBlockInfo(const DllBlockInfo* info,
398398
return true;
399399
}
400400

401-
if (info->mFlags & DllBlockInfo::USE_TIMESTAMP) {
401+
if (info.mFlags & DllBlockInfo::USE_TIMESTAMP) {
402402
*fVersion = GetTimestamp(full_fname.get());
403-
if (*fVersion > info->mMaxVersion) {
403+
if (*fVersion > info.mMaxVersion) {
404404
return false;
405405
}
406406
} else {
407407
LauncherResult<ModuleVersion> version =
408408
GetModuleVersion(full_fname.get());
409409

410410
if (version.isOk()) {
411-
return info->IsVersionBlocked(version.unwrap());
411+
return info.IsVersionBlocked(version.unwrap());
412412
}
413413
}
414414
}
415415

416416
return true;
417417
}
418418

419+
struct CaseSensitiveStringComparator {
420+
explicit CaseSensitiveStringComparator(const char* aTarget)
421+
: mTarget(aTarget) {}
422+
423+
int operator()(const DllBlockInfo& aVal) const {
424+
return strcmp(mTarget, aVal.mName);
425+
}
426+
427+
const char* mTarget;
428+
};
429+
419430
static NTSTATUS NTAPI patched_LdrLoadDll(PWCHAR filePath, PULONG flags,
420431
PUNICODE_STRING moduleFileName,
421432
PHANDLE handle) {
@@ -509,21 +520,26 @@ static NTSTATUS NTAPI patched_LdrLoadDll(PWCHAR filePath, PULONG flags,
509520

510521

511522
DECLARE_POINTER_TO_FIRST_DLL_BLOCKLIST_ENTRY(info);
512-
while (info->mName) {
513-
if (strcmp(info->mName, dllName) == 0) {
523+
DECLARE_DLL_BLOCKLIST_NUM_ENTRIES(infoNumEntries);
524+
CaseSensitiveStringComparator comp(dllName);
525+
size_t match = LowerBound(info, 0, infoNumEntries, comp);
526+
if (match != infoNumEntries) {
527+
528+
529+
530+
while (match < infoNumEntries && (comp(info[match]) == 0)) {
514531
unsigned long long fVersion;
515-
if (ShouldBlockBasedOnBlockInfo(info, dllName, filePath, fname,
532+
if (ShouldBlockBasedOnBlockInfo(info[match], dllName, filePath, fname,
516533
&fVersion)) {
517534
printf_stderr(
518535
"LdrLoadDll: Blocking load of '%s' -- see "
519536
"http://www.mozilla.com/en-US/blocklist/\n",
520537
dllName);
521-
DllBlockSet::Add(info->mName, fVersion);
538+
DllBlockSet::Add(info[match].mName, fVersion);
522539
return STATUS_DLL_NOT_FOUND;
523540
}
541+
++match;
524542
}
525-
526-
info++;
527543
}
528544
}
529545

0 commit comments

Comments
 (0)