From 7c95913c61b4b08de14325373e07a4f73af10506 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 5 Mar 2011 09:07:16 +0900 Subject: [PATCH] Avoid segfaulting with bad string relocs. --- tools/qfcc/source/linker.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/linker.c b/tools/qfcc/source/linker.c index d02ae2ac4..2991caf00 100644 --- a/tools/qfcc/source/linker.c +++ b/tools/qfcc/source/linker.c @@ -803,7 +803,15 @@ process_loose_relocs (qfo_t *qfo) } reloc->space = qfo->spaces[reloc->space].id; 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); } if (!reloc->space) {