From fa7f6a5176a386f8847810f34538d5c0e56f0fb1 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 2 Oct 2024 13:12:16 -0600 Subject: lib9p: Rename checksize to validate --- lib9p/include/lib9p/9p.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lib9p/include') diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index b33ae96..1c8f2e5 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -26,9 +26,12 @@ int lib9p_error(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *msg); int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, ...); /** - * Return how much space the message at net_bytes will take when - * unmarshaled. This number may be larger than net_bytes due to (1) - * struct padding, (2) nul-terminator byes for strings. + * Validate a message's structure; it's size, string encodings, enums, + * and bitfields. + * + * Return how much space the message will take when unmarshaled. This + * number may be larger than net_bytes due to (1) struct padding, (2) + * nul-terminator bytes for strings. * * Emits an error (return -1, set ctx->err_num and ctx->err_msg) if * either the message type is unknown, or if net_bytes is too short @@ -39,10 +42,12 @@ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, . * * @return required size, or -1 on error * - * @errno LINUX_EBADMSG: message is too short for content + * @errno LINUX_EBADMSG: message is wrong size for content * @errno LINUX_EBADMSG: message contains invalid UTF-8 + * @errno LINUX_EBADMSG: message contains a bitfield with unknown bits + * @errno LINUX_EMSGSIZE: would-be return value overflows SSIZE_MAX */ -ssize_t lib9p_unmarshal_size(struct lib9p_ctx *ctx, uint8_t *net_bytes); +ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); /** * Unmarshal the 9P message `net_bytes` into the C struct `ret_body`. @@ -55,13 +60,13 @@ ssize_t lib9p_unmarshal_size(struct lib9p_ctx *ctx, uint8_t *net_bytes); * * @return ret_typ : the mesage type * @return ret_tag : the message-ID tag - * @return ret_body : the message body, must be at least lib9p_unmarshal_size() bytes + * @return ret_body : the message body, must be at least lib9p_validate() bytes */ void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, enum lib9p_msg_type *ret_typ, uint16_t *ret_tag, void *ret_body); /** - * Marshal a `struct lib9p_msg_{typ}` structure into a byte-array. + * Marshal a `struct lib9p_msg_{typ}` structure into a byte-array. * * @param ctx : negotiated protocol parameters, where to record errors * @param typ : the message type -- cgit v1.2.3-2-g168b