History

Fix relocs of unwanted sections

relocation sections to sections we don't want to handle lead to segfaults, handle this situation (by ignoring the relocs as well).

Michael Matz committed 7 years ago

Commit fef838d1 parent 749d19d1 file · +11 −3Browse files

Unified · Split

tccelf.c+11−3
@@ -2271,6 +2271,7 @@ static void *load_data(int fd, unsigned long file_offset, unsigned long size) · 2270 unmodified lines
2271typedef struct SectionMergeInfo {2271typedef struct SectionMergeInfo {
2272 Section *s; /* corresponding existing section */2272 Section *s; /* corresponding existing section */
2273 unsigned long offset; /* offset of the new section in the existing section */2273 unsigned long offset; /* offset of the new section in the existing section */
2274 unsigned long oldlen; /* size of existing section before adding this one */
2274 uint8_t new_section; /* true if section 's' was added */2275 uint8_t new_section; /* true if section 's' was added */
2275 uint8_t link_once; /* true if link once section */2276 uint8_t link_once; /* true if link once section */
2276} SectionMergeInfo;2277} SectionMergeInfo;
@@ -2421,6 +2422,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 144 unmodified lines
2421 }2422 }
2422 2423
2423 /* align start of section */2424 /* align start of section */
2425 sm_table[i].oldlen = s->data_offset;
2424 offset = s->data_offset;2426 offset = s->data_offset;
2425 2427
2426 if (0 == strcmp(sh_name, ".stab")) {2428 if (0 == strcmp(sh_name, ".stab")) {
@@ -2478,9 +2480,15 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 51 unmodified lines
2478 if (sh->sh_link > 0)2480 if (sh->sh_link > 0)
2479 s->link = sm_table[sh->sh_link].s;2481 s->link = sm_table[sh->sh_link].s;
2480 if (sh->sh_type == SHT_RELX) {2482 if (sh->sh_type == SHT_RELX) {
2481 s->sh_info = sm_table[sh->sh_info].s->sh_num;2483 if (sm_table[sh->sh_info].s) {
2482 /* update backward link */2484 s->sh_info = sm_table[sh->sh_info].s->sh_num;
2483 s1->sections[s->sh_info]->reloc = s;2485 /* update backward link */
2486 s1->sections[s->sh_info]->reloc = s;
2487 } else {
2488 /* we haven't read the target of relocs, so cancel them */
2489 s->data_offset = sm_table[i].oldlen;
2490 sm_table[i].s = NULL;
2491 }
2484 }2492 }
2485 }2493 }
2486 sm = sm_table;2494 sm = sm_table;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t