vrend_renderer: Check the shader terminator

Submitted by Po-Hsien Wang on Aug. 14, 2018, 10:32 a.m.

Details

Message ID 20180814103227.124158-1-pwang@chromium.org
State New
Series "vrend_renderer: Check the shader terminator"
Headers show

Commit Message

Po-Hsien Wang Aug. 14, 2018, 10:32 a.m.
1) In the decode phase, increase the shader header size by 1 as 
   the shader has to be at least contains one terminate character.
2) Before calling tgsi_text_translate, check the last 4 bytes of
   shader contains the terminating character.

TEST=WebGLAquarium
---
 src/virgl_protocol.h | 2 +-
 src/vrend_renderer.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/virgl_protocol.h b/src/virgl_protocol.h
index dd1a4ee..ade213c 100644
--- a/src/virgl_protocol.h
+++ b/src/virgl_protocol.h
@@ -214,7 +214,7 @@  enum virgl_context_cmd {
 #define VIRGL_OBJ_CLEAR_STENCIL 8
 
 /* shader object */
-#define VIRGL_OBJ_SHADER_HDR_SIZE(nso) (5 + ((nso) ? (2 * nso) + 4 : 0))
+#define VIRGL_OBJ_SHADER_HDR_SIZE(nso) (6 + ((nso) ? (2 * nso) + 4 : 0))
 #define VIRGL_OBJ_SHADER_HANDLE 1
 #define VIRGL_OBJ_SHADER_TYPE 2
 #define VIRGL_OBJ_SHADER_OFFSET 3
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 57f3a1b..e7238d9 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -3027,7 +3027,11 @@  int vrend_create_shader(struct vrend_context *ctx,
 
       if (vrend_dump_shaders)
          fprintf(stderr,"shader\n%s\n", shd_text);
-      if (!tgsi_text_translate((const char *)shd_text, tokens, num_tokens + 10)) {
+
+      int last_chunk_offset = sel->buf_offset ? sel->buf_offset : pkt_length * 4;
+      if (!memchr(shd_text + last_chunk_offset - 4, '\0', 4) ||
+          !tgsi_text_translate((const char *)shd_text, tokens, num_tokens + 10)) {
+         fprintf(stderr, "not valid\n");
          free(tokens);
          ret = EINVAL;
          goto error;