aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-12 22:07:34 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-12 22:07:34 +0100
commit73afb2c5bb06365f913a7992a555ae34d74eb946 (patch)
treeb4089e8c558868da9d5aec4a6fabde7df4bc62b3
parenta68295151788760d694ef136b00c773973aba772 (diff)
downloadtr8vm-73afb2c5bb06365f913a7992a555ae34d74eb946.tar.gz
tr8vm-73afb2c5bb06365f913a7992a555ae34d74eb946.zip
Check for overflow
-rw-r--r--tr8as.c6
1 files changed, 6 insertions, 0 deletions
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)