guard against circular section merges

This commit is contained in:
Nikita Smith
2025-06-25 10:53:23 -07:00
committed by Ryan Fleury
parent 2e531cd70a
commit c2b3634e7a
2 changed files with 14 additions and 0 deletions
+13
View File
@@ -275,6 +275,19 @@ lnk_section_table_merge(LNK_SectionTable *sectab, LNK_MergeDirectiveList merge_l
}
}
}
// guard against circular merges
{
if (str8_match(merge_node->data.dst, merge_node->data.src, 0)) {
lnk_error(LNK_Error_CircularMerge, "detected circular /MERGE:%S=%S", merge_node->data.src, merge_node->data.dst);
}
for (LNK_SectionNode *sect_n = sectab->merge_list.first; sect_n != 0; sect_n = sect_n->next) {
if (str8_match(sect_n->data.name, merge_node->data.dst, 0) ||
str8_match(sect_n->data.name, merge_node->data.src, 0)) {
lnk_error(LNK_Error_CircularMerge, "detected circular /MERGE:%S=%S", merge_node->data.src, merge_node->data.dst);
}
}
}
// are we trying to merge section that was already merged?
LNK_Section *merge_sect = 0;