protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

commit 9fab8459e141b2e2b037f214530bd19a788450ca
parent 0fdbd4e6781a8b7759bfc9432793e2815517ec4f
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 15 Jul 2021 10:29:22 -0700

make sure to limit custom sections

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/wasm.c | 3+++
Msrc/wasm.h | 3++-
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/wasm.c b/src/wasm.c @@ -1337,6 +1337,9 @@ static int parse_custom_section(struct wasm_parser *p, u32 size, u8 *start; start = p->cur.p; + if (p->module.custom_sections + 1 > MAX_CUSTOM_SECTIONS) + return parse_err(p, "more than 32 custom sections!"); + if (!parse_name(p, &section->name)) return parse_err(p, "name"); diff --git a/src/wasm.h b/src/wasm.h @@ -7,6 +7,7 @@ static const unsigned char WASM_MAGIC[] = {0,'a','s','m'}; #define WASM_VERSION 0x01 #define MAX_U32_LEB128_BYTES 5 #define MAX_U64_LEB128_BYTES 10 +#define MAX_CUSTOM_SECTIONS 32 #define FUNC_TYPE_TAG 0x60 @@ -420,7 +421,7 @@ struct startsec { struct module { unsigned int parsed; unsigned int custom_sections; - struct customsec custom_section[32]; + struct customsec custom_section[MAX_CUSTOM_SECTIONS]; struct typesec type_section; struct funcsec func_section; struct importsec import_section;