Avoid segfaulting with bad string relocs.

This commit is contained in:
Bill Currie 2011-03-05 09:07:16 +09:00
parent 8eb5fd653a
commit 7c95913c61
1 changed files with 9 additions and 1 deletions

View File

@ -803,7 +803,15 @@ process_loose_relocs (qfo_t *qfo)
} }
reloc->space = qfo->spaces[reloc->space].id; reloc->space = qfo->spaces[reloc->space].id;
if (reloc->type == rel_def_string) { if (reloc->type == rel_def_string) {
const char *str = QFO_GSTRING (qfo, reloc->space, reloc->offset); const char *str;
if (reloc->target < 0
|| reloc->target >= qfo->spaces[qfo_strings_space].data_size) {
linker_error ("bad string reloc at %d:%x", reloc->space,
reloc->offset);
reloc->target = 0;
}
str = QFOSTR (qfo, reloc->target);
reloc->target = linker_add_string (str); reloc->target = linker_add_string (str);
} }
if (!reloc->space) { if (!reloc->space) {