aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorMichael Forney <[email protected]>2024-03-26 11:04:42 -0700
committerQuentin Carbonneaux <[email protected]>2024-03-28 10:35:11 +0100
commit85827e2232d65920ddc2d6323d9dea8f9de0cf89 (patch)
treea5849faf238a207e4ea0731127681f0325868f66 /parse.c
parent1b7770e271252cf01ec2e13b97c82922387e3e41 (diff)
check that data alignment is in range and a power of two
Otherwise, the alignment gets truncated to fit in char, so `align 256` is handled as no alignment requirement.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index 738ec5b..3717a6f 100644
--- a/parse.c
+++ b/parse.c
@@ -1091,6 +1091,9 @@ parsedat(void cb(Dat *), Lnk *lnk)
if (t == Talign) {
if (nextnl() != Tint)
err("alignment expected");
+ if (tokval.num <= 0 || tokval.num > CHAR_MAX
+ || (tokval.num & (tokval.num-1)) != 0)
+ err("invalid alignment");
lnk->align = tokval.num;
t = nextnl();
}