diff options
Diffstat (limited to 'lib9p/types.c')
-rw-r--r-- | lib9p/types.c | 264 |
1 files changed, 132 insertions, 132 deletions
diff --git a/lib9p/types.c b/lib9p/types.c index c4812d1..8582161 100644 --- a/lib9p/types.c +++ b/lib9p/types.c @@ -288,9 +288,9 @@ const char *lib9p_msg_type_str(enum lib9p_msg_type typ) { return msg_type_strs[typ]; } -/* checksize_* (internals of unmarshal_size()) ********************************/ +/* validate_* *****************************************************************/ -static ALWAYS_INLINE bool _checksize_net(struct _checksize_ctx *ctx, uint32_t n) { +static ALWAYS_INLINE bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) { if (__builtin_add_overflow(ctx->net_offset, n, &ctx->net_offset)) /* If needed-net-size overflowed uint32_t, then * there's no way that actual-net-size will live up to @@ -301,7 +301,7 @@ static ALWAYS_INLINE bool _checksize_net(struct _checksize_ctx *ctx, uint32_t n) return false; } -static ALWAYS_INLINE bool _checksize_host(struct _checksize_ctx *ctx, size_t n) { +static ALWAYS_INLINE bool _validate_size_host(struct _validate_ctx *ctx, size_t n) { if (__builtin_add_overflow(ctx->host_extra, n, &ctx->host_extra)) /* If needed-host-size overflowed size_t, then there's * no way that actual-net-size will live up to @@ -310,223 +310,223 @@ static ALWAYS_INLINE bool _checksize_host(struct _checksize_ctx *ctx, size_t n) return false; } -static ALWAYS_INLINE bool _checksize_list(struct _checksize_ctx *ctx, - size_t cnt, _checksize_fn_t item_fn, size_t item_host_size) { +static ALWAYS_INLINE bool _validate_list(struct _validate_ctx *ctx, + size_t cnt, _validate_fn_t item_fn, size_t item_host_size) { for (size_t i = 0; i < cnt; i++) - if (_checksize_host(ctx, item_host_size) || item_fn(ctx)) + if (_validate_size_host(ctx, item_host_size) || item_fn(ctx)) return true; return false; } -#define checksize_1(ctx) _checksize_net(ctx, 1) -#define checksize_2(ctx) _checksize_net(ctx, 2) -#define checksize_4(ctx) _checksize_net(ctx, 4) -#define checksize_8(ctx) _checksize_net(ctx, 8) +#define validate_1(ctx) _validate_size_net(ctx, 1) +#define validate_2(ctx) _validate_size_net(ctx, 2) +#define validate_4(ctx) _validate_size_net(ctx, 4) +#define validate_8(ctx) _validate_size_net(ctx, 8) -static ALWAYS_INLINE bool checksize_d(struct _checksize_ctx *ctx) { +static ALWAYS_INLINE bool validate_d(struct _validate_ctx *ctx) { uint32_t base_offset = ctx->net_offset; - if (checksize_4(ctx)) + if (validate_4(ctx)) return true; uint32_t len = decode_u32le(&ctx->net_bytes[base_offset]); - return _checksize_net(ctx, len) || _checksize_host(ctx, len); + return _validate_size_net(ctx, len) || _validate_size_host(ctx, len); } -static ALWAYS_INLINE bool checksize_s(struct _checksize_ctx *ctx) { +static ALWAYS_INLINE bool validate_s(struct _validate_ctx *ctx) { uint32_t base_offset = ctx->net_offset; - if (checksize_2(ctx)) + if (validate_2(ctx)) return true; uint16_t len = decode_u16le(&ctx->net_bytes[base_offset]); - if (_checksize_net(ctx, len) || _checksize_host(ctx, ((size_t)len)+1)) + if (_validate_size_net(ctx, len) || _validate_size_host(ctx, ((size_t)len)+1)) return true; if (!is_valid_utf8_without_nul(&ctx->net_bytes[base_offset+2], len)) return lib9p_error(ctx->ctx, LINUX_EBADMSG, "message contains invalid UTF-8"); return false; } -static ALWAYS_INLINE bool checksize_qid(struct _checksize_ctx *ctx) { - return checksize_qt(ctx) - || checksize_4(ctx) - || checksize_8(ctx); +static ALWAYS_INLINE bool validate_qid(struct _validate_ctx *ctx) { + return validate_qt(ctx) + || validate_4(ctx) + || validate_8(ctx); } -static ALWAYS_INLINE bool checksize_stat(struct _checksize_ctx *ctx) { - return checksize_2(ctx) - || checksize_2(ctx) - || checksize_4(ctx) - || checksize_qid(ctx) - || checksize_4(ctx) - || checksize_4(ctx) - || checksize_4(ctx) - || checksize_8(ctx) - || checksize_s(ctx) - || checksize_s(ctx) - || checksize_s(ctx) - || checksize_s(ctx) - || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && checksize_s(ctx) ) - || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && checksize_4(ctx) ) - || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && checksize_4(ctx) ) - || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && checksize_4(ctx) ); +static ALWAYS_INLINE bool validate_stat(struct _validate_ctx *ctx) { + return validate_2(ctx) + || validate_2(ctx) + || validate_4(ctx) + || validate_qid(ctx) + || validate_4(ctx) + || validate_4(ctx) + || validate_4(ctx) + || validate_8(ctx) + || validate_s(ctx) + || validate_s(ctx) + || validate_s(ctx) + || validate_s(ctx) + || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && validate_s(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) ); } -static FLATTEN bool checksize_Tversion(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_s(ctx); +static FLATTEN bool validate_Tversion(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_s(ctx); } -static FLATTEN bool checksize_Rversion(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_s(ctx); +static FLATTEN bool validate_Rversion(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_s(ctx); } -static FLATTEN bool checksize_Tauth(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_s(ctx) - || checksize_s(ctx) - || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && checksize_4(ctx) ); +static FLATTEN bool validate_Tauth(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_s(ctx) + || validate_s(ctx) + || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && validate_4(ctx) ); } -static FLATTEN bool checksize_Rauth(struct _checksize_ctx *ctx) { - return checksize_qid(ctx); +static FLATTEN bool validate_Rauth(struct _validate_ctx *ctx) { + return validate_qid(ctx); } -static FLATTEN bool checksize_Tattach(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_4(ctx) - || checksize_s(ctx) - || checksize_s(ctx); +static FLATTEN bool validate_Tattach(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_4(ctx) + || validate_s(ctx) + || validate_s(ctx); } -static FLATTEN bool checksize_Rattach(struct _checksize_ctx *ctx) { - return checksize_qid(ctx); +static FLATTEN bool validate_Rattach(struct _validate_ctx *ctx) { + return validate_qid(ctx); } -static FLATTEN bool checksize_Rerror(struct _checksize_ctx *ctx) { - return checksize_s(ctx) - || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && checksize_4(ctx) ); +static FLATTEN bool validate_Rerror(struct _validate_ctx *ctx) { + return validate_s(ctx) + || ( (ctx->ctx->version==LIB9P_VER_9P2000_u) && validate_4(ctx) ); } -static FLATTEN bool checksize_Tflush(struct _checksize_ctx *ctx) { - return checksize_2(ctx); +static FLATTEN bool validate_Tflush(struct _validate_ctx *ctx) { + return validate_2(ctx); } -static FLATTEN bool checksize_Rflush(struct _checksize_ctx *UNUSED(ctx)) { +static FLATTEN bool validate_Rflush(struct _validate_ctx *UNUSED(ctx)) { return false; } -static FLATTEN bool checksize_Twalk(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_4(ctx) - || checksize_2(ctx) - || _checksize_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), checksize_s, sizeof(struct lib9p_s)); +static FLATTEN bool validate_Twalk(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_4(ctx) + || validate_2(ctx) + || _validate_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), validate_s, sizeof(struct lib9p_s)); } -static FLATTEN bool checksize_Rwalk(struct _checksize_ctx *ctx) { - return checksize_2(ctx) - || _checksize_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), checksize_qid, sizeof(struct lib9p_qid)); +static FLATTEN bool validate_Rwalk(struct _validate_ctx *ctx) { + return validate_2(ctx) + || _validate_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), validate_qid, sizeof(struct lib9p_qid)); } -static FLATTEN bool checksize_Topen(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_1(ctx); +static FLATTEN bool validate_Topen(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_1(ctx); } -static FLATTEN bool checksize_Ropen(struct _checksize_ctx *ctx) { - return checksize_qid(ctx) - || checksize_4(ctx); +static FLATTEN bool validate_Ropen(struct _validate_ctx *ctx) { + return validate_qid(ctx) + || validate_4(ctx); } -static FLATTEN bool checksize_Tcreate(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_s(ctx) - || checksize_4(ctx) - || checksize_1(ctx); +static FLATTEN bool validate_Tcreate(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_s(ctx) + || validate_4(ctx) + || validate_1(ctx); } -static FLATTEN bool checksize_Rcreate(struct _checksize_ctx *ctx) { - return checksize_qid(ctx) - || checksize_4(ctx); +static FLATTEN bool validate_Rcreate(struct _validate_ctx *ctx) { + return validate_qid(ctx) + || validate_4(ctx); } -static FLATTEN bool checksize_Tread(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_8(ctx) - || checksize_4(ctx); +static FLATTEN bool validate_Tread(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_8(ctx) + || validate_4(ctx); } -static FLATTEN bool checksize_Rread(struct _checksize_ctx *ctx) { - return checksize_d(ctx); +static FLATTEN bool validate_Rread(struct _validate_ctx *ctx) { + return validate_d(ctx); } -static FLATTEN bool checksize_Twrite(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_8(ctx) - || checksize_d(ctx); +static FLATTEN bool validate_Twrite(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_8(ctx) + || validate_d(ctx); } -static FLATTEN bool checksize_Rwrite(struct _checksize_ctx *ctx) { - return checksize_4(ctx); +static FLATTEN bool validate_Rwrite(struct _validate_ctx *ctx) { + return validate_4(ctx); } -static FLATTEN bool checksize_Tclunk(struct _checksize_ctx *ctx) { - return checksize_4(ctx); +static FLATTEN bool validate_Tclunk(struct _validate_ctx *ctx) { + return validate_4(ctx); } -static FLATTEN bool checksize_Rclunk(struct _checksize_ctx *UNUSED(ctx)) { +static FLATTEN bool validate_Rclunk(struct _validate_ctx *UNUSED(ctx)) { return false; } -static FLATTEN bool checksize_Tremove(struct _checksize_ctx *ctx) { - return checksize_4(ctx); +static FLATTEN bool validate_Tremove(struct _validate_ctx *ctx) { + return validate_4(ctx); } -static FLATTEN bool checksize_Rremove(struct _checksize_ctx *UNUSED(ctx)) { +static FLATTEN bool validate_Rremove(struct _validate_ctx *UNUSED(ctx)) { return false; } -static FLATTEN bool checksize_Tstat(struct _checksize_ctx *ctx) { - return checksize_4(ctx); +static FLATTEN bool validate_Tstat(struct _validate_ctx *ctx) { + return validate_4(ctx); } -static FLATTEN bool checksize_Rstat(struct _checksize_ctx *ctx) { - return checksize_stat(ctx); +static FLATTEN bool validate_Rstat(struct _validate_ctx *ctx) { + return validate_stat(ctx); } -static FLATTEN bool checksize_Twstat(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_stat(ctx); +static FLATTEN bool validate_Twstat(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_stat(ctx); } -static FLATTEN bool checksize_Rwstat(struct _checksize_ctx *UNUSED(ctx)) { +static FLATTEN bool validate_Rwstat(struct _validate_ctx *UNUSED(ctx)) { return false; } -static FLATTEN bool checksize_Tsession(struct _checksize_ctx *ctx) { - return checksize_8(ctx); +static FLATTEN bool validate_Tsession(struct _validate_ctx *ctx) { + return validate_8(ctx); } -static FLATTEN bool checksize_Rsession(struct _checksize_ctx *UNUSED(ctx)) { +static FLATTEN bool validate_Rsession(struct _validate_ctx *UNUSED(ctx)) { return false; } -static FLATTEN bool checksize_Tsread(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_2(ctx) - || _checksize_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), checksize_s, sizeof(struct lib9p_s)); +static FLATTEN bool validate_Tsread(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_2(ctx) + || _validate_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), validate_s, sizeof(struct lib9p_s)); } -static FLATTEN bool checksize_Rsread(struct _checksize_ctx *ctx) { - return checksize_d(ctx); +static FLATTEN bool validate_Rsread(struct _validate_ctx *ctx) { + return validate_d(ctx); } -static FLATTEN bool checksize_Tswrite(struct _checksize_ctx *ctx) { - return checksize_4(ctx) - || checksize_2(ctx) - || _checksize_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), checksize_s, sizeof(struct lib9p_s)) - || checksize_d(ctx); +static FLATTEN bool validate_Tswrite(struct _validate_ctx *ctx) { + return validate_4(ctx) + || validate_2(ctx) + || _validate_list(ctx, decode_u16le(&ctx->net_bytes[ctx->net_offset-2]), validate_s, sizeof(struct lib9p_s)) + || validate_d(ctx); } -static FLATTEN bool checksize_Rswrite(struct _checksize_ctx *ctx) { - return checksize_4(ctx); +static FLATTEN bool validate_Rswrite(struct _validate_ctx *ctx) { + return validate_4(ctx); } /* unmarshal_* ****************************************************************/ @@ -1067,11 +1067,11 @@ static FLATTEN bool marshal_Rswrite(struct _marshal_ctx *ctx, struct lib9p_msg_R /* vtables ********************************************************************/ -#define _MSG(typ) [LIB9P_TYP_##typ] = { \ - .unmarshal_basesize = sizeof(struct lib9p_msg_##typ), \ - .unmarshal_extrasize = checksize_##typ, \ - .unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \ - .marshal = (_marshal_fn_t)marshal_##typ, \ +#define _MSG(typ) [LIB9P_TYP_##typ] = { \ + .basesize = sizeof(struct lib9p_msg_##typ), \ + .validate = validate_##typ, \ + .unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \ + .marshal = (_marshal_fn_t)marshal_##typ, \ } struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM] = { |