vrend: cleanup emit_string_marker command buffer decoding

Follow up to commit a108be89e3 to clarify
acceptable length values for VIRGL_CCMD_SEND_STRING_MARKER command
buffers. This imposes no functional change.

Signed-off-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Ryan Neph 3 years ago committed by Chia-I Wu
parent 6428beead4
commit 583961a7ed
  1. 13
      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) 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) { if (length < VIRGL_SEND_STRING_MARKER_MIN_SIZE) {
fprintf(stderr, "minimal command length not okay\n"); fprintf(stderr, "minimal command length not okay\n");
return EINVAL; return EINVAL;
} }
int32_t len = get_buf_entry(buf, VIRGL_SEND_STRING_MARKER_STRING_SIZE); uint32_t str_len = get_buf_entry(buf, VIRGL_SEND_STRING_MARKER_STRING_SIZE);
if (len < 0) { if (str_len > buf_len) {
fprintf(stderr, "String len %d < 0\n", len); fprintf(stderr, "String len %u > buf_len %u\n", str_len, buf_len);
return EINVAL;
} else if (len > buf_len) {
fprintf(stderr, "String len %d > buf_len %d\n", len, buf_len);
return EINVAL; 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; return 0;
} }

Loading…
Cancel
Save