summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib9p/protogen/c.py5
-rw-r--r--lib9p/srv.c12
2 files changed, 12 insertions, 5 deletions
diff --git a/lib9p/protogen/c.py b/lib9p/protogen/c.py
index a6824ce..363f0df 100644
--- a/lib9p/protogen/c.py
+++ b/lib9p/protogen/c.py
@@ -122,6 +122,11 @@ def gen_c(versions: set[str], typs: list[idl.UserType]) -> str:
ret += f"const struct {c9util.ident('_ver_tentry')} {c9util.ident('_table_ver')}[{c9util.ver_enum('NUM')}] = {{\n"
rerror = next(typ for typ in typs if typ.typname == "Rerror")
for ver in ["unknown", *sorted(versions)]:
+ # XXX: There are good arguments that min_msg_size should be
+ # something larger than rerror.min_size().
+ # srv.c:respond_error() assumes that min_msg_size is
+ # rerror.min_size(); if you do change min_msg_size to
+ # something larger, then be sure to update respond_error().
if ver == "unknown":
min_msg_size = rerror.min_size("9P2000") # SPECIAL (initialization)
else:
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 5ff083f..836890c 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -127,7 +127,6 @@ struct _srv_sess {
struct _srv_conn *parent_conn;
enum lib9p_version version;
uint32_t max_msg_size;
- uint32_t rerror_overhead;
/* mutable */
bool initialized;
bool closing;
@@ -190,10 +189,15 @@ static void respond_error(struct _lib9p_srv_req *req) {
struct _srv_sess *sess = req->parent_sess;
+ /* XXX: This assumes that a version's min_msg_size is the
+ * Rerror overhead. That's true for the current
+ * implementation of protogen, but is a sneaky assumption. */
+ uint32_t overhead = lib9p_version_min_msg_size(sess->version);
+
/* Truncate the error-string if necessary to avoid needing to
* return LINUX_ERANGE. */
- if (((uint32_t)host.errstr.len) + sess->rerror_overhead > sess->max_msg_size)
- host.errstr.len = sess->max_msg_size - sess->rerror_overhead;
+ if (((uint32_t)host.errstr.len) + overhead > sess->max_msg_size)
+ host.errstr.len = sess->max_msg_size - overhead;
struct lib9p_Rmsg_send_buf net;
@@ -267,7 +271,6 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
.parent_conn = &conn,
.version = LIB9P_VER_unknown,
.max_msg_size = CONFIG_9P_SRV_MAX_MSG_SIZE,
- .rerror_overhead = lib9p_version_min_msg_size(LIB9P_VER_unknown),
.initialized = false,
};
for (;;) {
@@ -659,7 +662,6 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx,
/* Replace the old session with the new session. */
ctx->parent_sess->version = version;
ctx->parent_sess->max_msg_size = resp->max_msg_size;
- ctx->parent_sess->rerror_overhead = min_msg_size;
}
static void handle_Tauth(struct _lib9p_srv_req *ctx,