Browse Source

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.
Michael Forney 1 year ago
parent
commit
85827e2232
1 changed files with 3 additions and 0 deletions
  1. 3 0
      parse.c

+ 3 - 0
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();
 	}