From 583961a7ed225a309f9cdad2eeff25c85198acd1 Mon Sep 17 00:00:00 2001 From: Ryan Neph Date: Wed, 28 Jul 2021 13:54:20 -0700 Subject: [PATCH] vrend: cleanup emit_string_marker command buffer decoding Follow up to commit a108be89e36ad427bf5f9affdbb4dd434e119b28 to clarify acceptable length values for VIRGL_CCMD_SEND_STRING_MARKER command buffers. This imposes no functional change. Signed-off-by: Ryan Neph Reviewed-by: Chia-I Wu Reviewed-by: Yiwei Zhang --- src/vrend_decode.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/vrend_decode.c b/src/vrend_decode.c index c25a565..25a9204 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -1580,23 +1580,20 @@ static int vrend_decode_get_memory_info(struct vrend_context *ctx, const uint32_ static int vrend_decode_send_string_marker(struct vrend_context *ctx, const uint32_t *buf, uint32_t length) { - int buf_len = sizeof(uint32_t) * (length - 1); + uint32_t buf_len = sizeof(uint32_t) * (length - 1); if (length < VIRGL_SEND_STRING_MARKER_MIN_SIZE) { fprintf(stderr, "minimal command length not okay\n"); return EINVAL; } - int32_t len = get_buf_entry(buf, VIRGL_SEND_STRING_MARKER_STRING_SIZE); - if (len < 0) { - fprintf(stderr, "String len %d < 0\n", len); - return EINVAL; - } else if (len > buf_len) { - fprintf(stderr, "String len %d > buf_len %d\n", len, buf_len); + uint32_t str_len = get_buf_entry(buf, VIRGL_SEND_STRING_MARKER_STRING_SIZE); + if (str_len > buf_len) { + fprintf(stderr, "String len %u > buf_len %u\n", str_len, buf_len); return EINVAL; } - vrend_context_emit_string_marker(ctx, len, get_buf_ptr(buf, VIRGL_SEND_STRING_MARKER_OFFSET)); + vrend_context_emit_string_marker(ctx, str_len, get_buf_ptr(buf, VIRGL_SEND_STRING_MARKER_OFFSET)); return 0; }