Skip to content

Commit b1eb69f

Browse files
committed
fix(memhlp): Fix yet another segfault
Only happens on CachyOS
1 parent a5ec5c1 commit b1eb69f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/memhlp.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ lm_address_t MemHlp::patternScan(const char* pattern, lm_module_t module)
4545
//Totally unnecessary right now, and might always be
4646

4747
static auto codeSections = std::map<lm_address_t, lm_address_t>();
48+
codeSections.clear();
4849

49-
const static auto lambda = [](lm_segment_t* seg, lm_void_t* arg) -> lm_bool_t
50+
const static auto enumSections = [](lm_segment_t* seg, lm_void_t* arg) -> lm_bool_t
5051
{
5152
if(seg->prot & LM_PROT_R)
5253
{
@@ -57,10 +58,19 @@ lm_address_t MemHlp::patternScan(const char* pattern, lm_module_t module)
5758
return LM_TRUE;
5859
};
5960

60-
LM_EnumSegments(lambda, nullptr);
61+
LM_EnumSegments(enumSections, nullptr);
6162

6263
for(const auto& itm : codeSections)
6364
{
65+
if (module.base > itm.second)
66+
{
67+
continue;
68+
}
69+
if (module.base + module.size < itm.first)
70+
{
71+
continue;
72+
}
73+
6474
for (lm_address_t cur = itm.first; cur < itm.second; cur++)
6575
{
6676
bool found = true;

0 commit comments

Comments
 (0)