From 0a4e3bc737314e75748dfed8f97e670c2820cd5e Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 9 Nov 2022 09:40:25 +0100 Subject: shader: Use open coded string copy to avoid overflow Since we have to remove the swizzle part of the dest using an open coded loop should not more expensive then doing strcpy and strchr afterwards. Fixes Coverity ID 1527193: "Copy into fixed size buffer" Signed-off-by: Gert Wollny Part-of: --- src/vrend_shader.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 08995dd9..13569fda 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -3855,11 +3855,13 @@ translate_load(const struct dump_ctx *ctx, set_memory_qualifier(ssbo_memory_qualifier, ctx->ssbo_used_mask, inst, inst->Src[0].Register.Index, inst->Src[0].Register.Indirect); - strcpy(mydst, dst); - char *wmp = strchr(mydst, '.'); + const char *d = dst; + char *md = mydst; + unsigned i = 0; + while ((i < sizeof(mydst) - 1) && *d && *d != '.') + *md++ = *d++; + *md = 0; - if (wmp) - wmp[0] = 0; emit_buff(glsl_strbufs, "ssbo_addr_temp = uint(floatBitsToUint(%s)) >> 2;\n", srcs[1]); atomic_op[0] = atomic_src[0] = '\0'; -- cgit v1.2.3