From 73afb2c5bb06365f913a7992a555ae34d74eb946 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 12 May 2023 22:07:34 +0100 Subject: Check for overflow --- tr8as.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tr8as.c b/tr8as.c index 0237683..5e57b81 100644 --- a/tr8as.c +++ b/tr8as.c @@ -719,6 +719,9 @@ static uint8_t parse_db(As *as, char **c) else if (!new_ref(as, word, 0xff, as->addr)) return 0; + if (as->addr + 1 > UINT16_MAX) + return error_l("Memory overflow", &as->loc, "output is more than 65535 bytes"); + as->out[as->addr++] = imm & 0xff; if (as->addr > as->size) as->size = as->addr; @@ -754,6 +757,9 @@ static uint8_t parse_dw(As *as, char **c) && !new_ref(as, word, 0xffff, as->addr)) return 0; + if (as->addr + 2 > UINT16_MAX) + return error_l("Memory overflow", &as->loc, "output is more than 65535 bytes"); + as->out[as->addr++] = imm & 0xff; as->out[as->addr++] = imm >> 8; if (as->addr > as->size) -- cgit v1.2.3