From 558e8f46ff578f713147343148c8b46e789c965f Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Thu, 16 Jan 2020 12:37:54 +0100 Subject: [PATCH] Sanity check fixed address of sections in RGBLINK This could otherwise cause segfaults while reporting errors (!) during placement --- src/link/section.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/link/section.c b/src/link/section.c index 3a2c296b..9ea3474c 100644 --- a/src/link/section.c +++ b/src/link/section.c @@ -134,7 +134,7 @@ static void doSanityChecks(struct Section *section, void *ptr) /* Check if section has a chance to be placed */ if (section->size > maxsize[section->type]) - errx(1, "Section \"%s\" is bigger than the max size for that type: %#X > %#X", + errx(1, "Section \"%s\" is bigger than the max size for that type: %#x > %#x", section->size, maxsize[section->type]); /* Translate loose constraints to strong ones when they're equivalent */ @@ -160,6 +160,20 @@ static void doSanityChecks(struct Section *section, void *ptr) section->isAddressFixed = true; } } + + if (section->isAddressFixed) { + /* Ensure the target address is valid */ + if (section->org < startaddr[section->type] + || section->org > endaddr(section->type)) + errx(1, "Section \"%s\"'s fixed address %#x is outside of range [%#x; %#x]", + section->name, section->org, + startaddr[section->type], endaddr(section->type)); + + if (section->org + section->size > endaddr(section->type) + 1) + errx(1, "Section \"%s\"'s end address %#x is greater than last address %#x", + section->name, section->org + section->size, + endaddr(section->type) + 1); + } } void sect_DoSanityChecks(void)