From ed520678404ade3b5886be3f3c41a4bf41cf231d Mon Sep 17 00:00:00 2001 From: Andreas Klebinger Date: Wed, 4 Sep 2019 15:34:09 +0200 Subject: Fix bounds check in ocResolve_PEi386 for relocation values. The old test was wrong at least for gcc and the value -2287728808L. It also relied on implementation defined behaviour (right shift on a negative value), which might or might not be ok. Either way it's now a simple comparison which will always work. --- rts/linker/PEi386.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c index 6cf0d52d39..f2c49f6513 100644 --- a/rts/linker/PEi386.c +++ b/rts/linker/PEi386.c @@ -1961,14 +1961,14 @@ ocResolve_PEi386 ( ObjectCode* oc ) { intptr_t v; v = S + (int32_t)A - ((intptr_t)pP) - 4; - if ((v >> 32) && ((-v) >> 32)) { + if ((v > (intptr_t) INT32_MAX) || (v < (intptr_t) INT32_MIN)) { /* Make the trampoline then */ copyName (getSymShortName (info, sym), oc, symbol, sizeof(symbol)-1); S = makeSymbolExtra_PEi386(oc, symIndex, S, (char *)symbol); /* And retry */ v = S + (int32_t)A - ((intptr_t)pP) - 4; - if ((v >> 32) && ((-v) >> 32)) { + if ((v > (intptr_t) INT32_MAX) || (v < (intptr_t) INT32_MIN)) { barf("IMAGE_REL_AMD64_REL32: High bits are set in %zx for %s", v, (char *)symbol); } -- cgit v1.2.1