summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 08ccfc3..6d9d992 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -393,10 +393,7 @@ static void srv_respond_error(struct 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 core_gen, but is a sneaky assumption. */
- uint32_t overhead = lib9p_version_min_msg_size(sess->version);
+ uint32_t overhead = lib9p_version_min_Rerror_size(sess->version);
/* Truncate the error-string if necessary to avoid needing to
* return LIB9P_ERRNO_L_ERANGE. */
@@ -469,7 +466,7 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
};
struct srv_sess sess = {
.parent_conn = &conn,
- .version = LIB9P_VER_unknown,
+ .version = LIB9P_VER_uninitialized,
.max_msg_size = CONFIG_9P_SRV_MAX_MSG_SIZE,
.initialized = false,
};
@@ -720,7 +717,7 @@ static void handle_Tversion(struct srv_req *ctx,
struct lib9p_msg_Tversion *req) {
srv_handler_common(ctx, version, req);
- enum lib9p_version version = LIB9P_VER_unknown;
+ enum lib9p_version version = LIB9P_VER_uninitialized;
if (req->version.len >= 6 &&
req->version.utf8[0] == '9' &&
@@ -748,7 +745,11 @@ static void handle_Tversion(struct srv_req *ctx,
#endif
}
- uint32_t min_msg_size = lib9p_version_min_msg_size(version);
+ /* XXX: There are good arguments that min_msg_size should be
+ * something larger than max(rerror.min_size(),
+ * rread.min_size()+1). */
+ uint32_t min_msg_size = _LIB9P_MAX(lib9p_version_min_Rerror_size(ctx->basectx.version),
+ lib9p_version_min_Rread_size(ctx->basectx.version)+1);
if (req->max_msg_size < min_msg_size) {
lib9p_errorf(&ctx->basectx,
LIB9P_ERRNO_L_EDOM, "requested max_msg_size is less than minimum for %s (%"PRIu32" < %"PRIu32")",
@@ -1175,6 +1176,9 @@ static void handle_Tread(struct srv_req *ctx,
/* TODO: serialize simultaneous reads to the same FID */
+ if (req->count > ctx->basectx.max_msg_size - lib9p_version_min_Rread_size(ctx->basectx.version))
+ req->count = ctx->basectx.max_msg_size - lib9p_version_min_Rread_size(ctx->basectx.version);
+
/* Check that the FID is valid for this. */
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
@@ -1205,7 +1209,7 @@ static void handle_Tread(struct srv_req *ctx,
goto tread_return;
}
/* Read. */
- resp.data = heap = malloc(req->count); /* TODO: cap req->count */
+ resp.data = heap = malloc(req->count);
resp.count = 0;
struct srv_pathinfo *dir_pathinfo = NULL;
for (;;) {