summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-08 12:08:39 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-08 12:08:59 -0600
commit2e1ce75974945e6acc5178b4d811740e52e83d6e (patch)
tree12fd2d4a3c10ad116ae854e8b677289de5a32b29 /lib9p
parenta7a64e15987ddbb7feae6cf2ff1aaaeb71dbed82 (diff)
lib9p: fix stat size
It does NOT include the u16 size field itself.
Diffstat (limited to 'lib9p')
-rwxr-xr-xlib9p/9p.gen6
-rw-r--r--lib9p/9p.generated.c6
2 files changed, 6 insertions, 6 deletions
diff --git a/lib9p/9p.gen b/lib9p/9p.gen
index 4dff97d..83bdcfe 100755
--- a/lib9p/9p.gen
+++ b/lib9p/9p.gen
@@ -697,7 +697,7 @@ static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx,
prev_size = member.static_size
if typ.name == "stat": # SPECIAL
assert typ.members[0].static_size
- ret += f"\n{prefix1}((uint32_t)decode_u{typ.members[0].static_size*8}le(&ctx->net_bytes[size_offset]) != ctx->net_offset - size_offset"
+ ret += f"\n{prefix1}((uint32_t)decode_u{typ.members[0].static_size*8}le(&ctx->net_bytes[size_offset]) != ctx->net_offset - (size_offset+{typ.members[0].static_size})"
ret += f'\n{prefix2}\t? lib9p_error(ctx->ctx, LINUX_EBADMSG, "stat size does not match stat contents")'
ret += f"\n{prefix2}\t: false)"
ret += ";\n"
@@ -874,9 +874,9 @@ static ALWAYS_INLINE bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) {
prefix = prefix1
if typ.name == "stat": # SPECIAL
assert typ.members[0].static_size
- ret += f"\n{prefix1}((ctx->net_offset - size_offset > UINT16_MAX)"
+ ret += f"\n{prefix1}((ctx->net_offset - (size_offset+{typ.members[0].static_size}) > UINT16_MAX)"
ret += f'\n{prefix2}\t? lib9p_error(ctx->ctx, LINUX_ERANGE, "stat object too large")'
- ret += f"\n{prefix2}\t: ({{ encode_u{typ.members[0].static_size*8}le((uint{typ.members[0].static_size*8}_t)(ctx->net_offset - size_offset), &ctx->net_bytes[size_offset]);"
+ ret += f"\n{prefix2}\t: ({{ encode_u{typ.members[0].static_size*8}le((uint{typ.members[0].static_size*8}_t)(ctx->net_offset - (size_offset+{typ.members[0].static_size})), &ctx->net_bytes[size_offset]);"
ret += f"\n{prefix2} false; }}))"
ret += ";\n"
ret += "}\n"
diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c
index 1fef571..b2243e2 100644
--- a/lib9p/9p.generated.c
+++ b/lib9p/9p.generated.c
@@ -400,7 +400,7 @@ static ALWAYS_INLINE bool validate_stat(struct _validate_ctx *ctx) {
|| ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && validate_4(ctx) )
|| ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && validate_4(ctx) )
|| ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && validate_4(ctx) )
- || ((uint32_t)decode_u16le(&ctx->net_bytes[size_offset]) != ctx->net_offset - size_offset
+ || ((uint32_t)decode_u16le(&ctx->net_bytes[size_offset]) != ctx->net_offset - (size_offset+2)
? lib9p_error(ctx->ctx, LINUX_EBADMSG, "stat size does not match stat contents")
: false);
}
@@ -965,9 +965,9 @@ static ALWAYS_INLINE bool marshal_stat(struct _marshal_ctx *ctx, struct lib9p_st
|| ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && marshal_4(ctx, &val->file_owner_n_uid) )
|| ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && marshal_4(ctx, &val->file_owner_n_gid) )
|| ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && marshal_4(ctx, &val->file_last_modified_n_uid) )
- || ((ctx->net_offset - size_offset > UINT16_MAX)
+ || ((ctx->net_offset - (size_offset+2) > UINT16_MAX)
? lib9p_error(ctx->ctx, LINUX_ERANGE, "stat object too large")
- : ({ encode_u16le((uint16_t)(ctx->net_offset - size_offset), &ctx->net_bytes[size_offset]);
+ : ({ encode_u16le((uint16_t)(ctx->net_offset - (size_offset+2)), &ctx->net_bytes[size_offset]);
false; }));
}