summaryrefslogtreecommitdiff
path: root/lib9p/core_gen
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-04-22 18:51:59 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-06 11:53:17 -0600
commit24e5d0ec1219e2dbb4b9510ef20833092a2b3871 (patch)
tree01bbcc34c6190fa1c35b2625e9ba1744b1447606 /lib9p/core_gen
parentf09b7435b3a5222597d27238226d23ec0cbd5bd2 (diff)
wip: Build with -Wconversionlukeshu/safe-conversion
I think this found a real bug in the dhcp packet parser. I don't think anything called lib9p_str{,n}() values that could be big enough, but their bounds-checking was broken.
Diffstat (limited to 'lib9p/core_gen')
-rw-r--r--lib9p/core_gen/c_marshal.py4
-rw-r--r--lib9p/core_gen/h.py4
2 files changed, 5 insertions, 3 deletions
diff --git a/lib9p/core_gen/c_marshal.py b/lib9p/core_gen/c_marshal.py
index 322e1ef..581ed92 100644
--- a/lib9p/core_gen/c_marshal.py
+++ b/lib9p/core_gen/c_marshal.py
@@ -78,7 +78,7 @@ class OffsetExpr:
if dsttyp:
if not oneline:
oneline.append("0")
- ret += f"{'\t'*indent_depth}{dsttyp} {dstvar} = {' + '.join(oneline)};\n"
+ ret += f"{'\t'*indent_depth}{dsttyp} {dstvar} = LM_SAFEDOWNCAST({dsttyp}, {' + '.join(oneline)});\n"
elif oneline:
ret += f"{'\t'*indent_depth}{dstvar} += {' + '.join(oneline)};\n"
ret += multiline
@@ -350,6 +350,8 @@ def gen_c_marshal(versions: set[str], typs: list[idl.UserType]) -> str:
return f"offsetof{''.join('_'+m.membname for m in path.elems[:-1])}_{sym}"
val = c9util.idl_expr(child.val, lookup_sym)
+ if child.typ.static_size < 32:
+ val = f"LM_SAFEDOWNCAST(uint{child.typ.static_size*8}_t, {val})"
else:
val = path.c_str("val->")
if isinstance(child.typ, idl.Bitfield):
diff --git a/lib9p/core_gen/h.py b/lib9p/core_gen/h.py
index 61775c1..378fc06 100644
--- a/lib9p/core_gen/h.py
+++ b/lib9p/core_gen/h.py
@@ -354,14 +354,14 @@ enum {c9util.ident('version')} {{
ret += "\n"
ret += f"struct {c9util.ident('Tmsg_send_buf')} {{\n"
- ret += "\tsize_t iov_cnt;\n"
+ ret += "\tint iov_cnt;\n"
ret += f"\tstruct iovec iov[{c9util.IDENT('TMSG_MAX_IOV')}];\n"
ret += f"\tuint8_t copied[{c9util.IDENT('TMSG_MAX_COPY')}];\n"
ret += "};\n"
ret += "\n"
ret += f"struct {c9util.ident('Rmsg_send_buf')} {{\n"
- ret += "\tsize_t iov_cnt;\n"
+ ret += "\tint iov_cnt;\n"
ret += f"\tstruct iovec iov[{c9util.IDENT('RMSG_MAX_IOV')}];\n"
ret += f"\tuint8_t copied[{c9util.IDENT('RMSG_MAX_COPY')}];\n"
ret += "};\n"