summaryrefslogtreecommitdiff
path: root/lib9p/types.gen
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 22:09:31 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 22:09:31 -0600
commit4d451f90eba193a4ca2848c4ac7acccda96ed008 (patch)
treee00a41587de365134032fbd1ceff124b5552a280 /lib9p/types.gen
parentad2027ae26e5d83eb42c9edaa90f7b278f9b0d3d (diff)
lib9p: Validate Twalk and Rwalk list sizes
Diffstat (limited to 'lib9p/types.gen')
-rwxr-xr-xlib9p/types.gen13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib9p/types.gen b/lib9p/types.gen
index da99c36..8b1b878 100755
--- a/lib9p/types.gen
+++ b/lib9p/types.gen
@@ -551,7 +551,11 @@ static ALWAYS_INLINE bool _validate_size_host(struct _validate_ctx *ctx, size_t
}
static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx,
- size_t cnt, _validate_fn_t item_fn, size_t item_host_size) {
+ size_t cnt, size_t max,
+ _validate_fn_t item_fn, size_t item_host_size) {
+ if (max && cnt > max)
+ return lib9p_errorf(ctx->ctx, LINUX_EBADMSG, "list size is too large (%zu > %zu)",
+ cnt, max);
for (size_t i = 0; i < cnt; i++)
if (_validate_size_host(ctx, item_host_size) || item_fn(ctx))
return true;
@@ -663,7 +667,12 @@ static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx,
ret += "( " + c_vercond(idprefix, member.ver) + " && "
if member.cnt is not None:
assert prev_size
- ret += f"_validate_list(ctx, decode_u{prev_size*8}le(&ctx->net_bytes[ctx->net_offset-{prev_size}]), validate_{member.typ.name}, sizeof({c_typename(idprefix, member.typ)}))"
+ maxelem = 0
+ if (
+ typ.name in ["Twalk", "Rwalk"] and member.name[:1] == "w"
+ ): # SPECIAL
+ maxelem = 16
+ ret += f"_validate_list(ctx, decode_u{prev_size*8}le(&ctx->net_bytes[ctx->net_offset-{prev_size}]), {maxelem}, validate_{member.typ.name}, sizeof({c_typename(idprefix, member.typ)}))"
else:
ret += f"validate_{member.typ.name}(ctx)"
if member.ver != struct_versions: