LF-3750 [#imx-2544] fix Out-of-bounds access
authorJiyu Yang <jiyu.yang@nxp.com>
Fri, 30 Apr 2021 09:34:45 +0000 (17:34 +0800)
committerJiyu Yang <jiyu.yang@nxp.com>
Wed, 12 May 2021 09:25:06 +0000 (17:25 +0800)
fix coverity issue CID 12329075 Out-of-bounds access
Signed-off-by: Jiyu Yang <jiyu.yang@nxp.com>
drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.c

index c3cd8f3..d3d4da1 100644 (file)
@@ -1587,19 +1587,14 @@ static int gc_clk_write(const char __user *buf, size_t count, void* data)
     size_t ret;
     char _buf[100];
 
-    memset((void*)_buf, 0, 100);
-
-    if (count > 100)
-    {
-        printk("Error: input buffer too large\n");
-    }
-
+    count = min_t(size_t, count, (sizeof(_buf)-1));
     ret = copy_from_user(_buf, buf, count);
     if (ret != 0)
     {
         printk("Error: lost data: %d\n", (int)ret);
-        return ret;
+        return -EFAULT;
     }
+    _buf[count] = 0;
 
     _set_clk(_buf);