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
22712271 typedef struct SectionMergeInfo {
22722272 Section *s; /* corresponding existing section */
22732273 unsigned long offset; /* offset of the new section in the existing section */
2274+ unsigned long oldlen; /* size of existing section before adding this one */
22742275 uint8_t new_section; /* true if section 's' was added */
22752276 uint8_t link_once; /* true if link once section */
22762277 } SectionMergeInfo;
@@ -2421,6 +2422,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 144 unmodified lines
24212422 }
24222423
24232424 /* align start of section */
2425+ sm_table[i].oldlen = s->data_offset;
24242426 offset = s->data_offset;
24252427
24262428 if (0 == strcmp(sh_name, ".stab")) {
@@ -2478,9 +2480,15 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 51 unmodified lines
24782480 if (sh->sh_link > 0)
24792481 s->link = sm_table[sh->sh_link].s;
24802482 if (sh->sh_type == SHT_RELX) {
2481− s->sh_info = sm_table[sh->sh_info].s->sh_num;
2482− /* update backward link */
2483− s1->sections[s->sh_info]->reloc = s;
2483+ if (sm_table[sh->sh_info].s) {
2484+ s->sh_info = sm_table[sh->sh_info].s->sh_num;
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+ }
24842492 }
24852493 }
24862494 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