[COMMON] bcm: fix stack overflow possibility.
authorSeokju Yoon <sukju.yoon@samsung.com>
Wed, 7 Dec 2016 04:19:12 +0000 (13:19 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:21:51 +0000 (20:21 +0300)
Change-Id: Ia87174a7f0f04dfaf2e03935f66348ec1119d50b
Signed-off-by: Seokju Yoon <sukju.yoon@samsung.com>
drivers/soc/samsung/exynos-bcm.c

index 3d60a0462141e467be25b6a0730c0d0b8c3bef14..93d9983cf98d8354ae9e6ef0a311f9d568ee0a33 100644 (file)
@@ -410,17 +410,16 @@ static ssize_t store_load_bcm_fw(struct device *dev,
        unsigned long flags;
        int ret;
        bool value = true;
-       char str[FILE_STR];
 
-       ret = sscanf(buf, "%s", str);
-       if (ret != 1) {
-               dev_err(dev, "failed sscanf %d\n", ret);
-               return -EINVAL;
-       }
-       if (str[0] == '0')
+       if (buf[0] == '0') {
                value = false;
-       else if (str[0] == '/')
-               strncpy(input_file, str, strlen(str) + 1);
+       } else if (buf[0] == '/' && strlen(buf) < FILE_STR) {
+               ret = sscanf(buf, "%s", input_file);
+               if (ret != 1) {
+                       dev_err(dev, "failed sscanf %d\n", ret);
+                       return -EINVAL;
+               }
+       }
 
        /* bcm stop and pd unprepare */
        if (fw_func) {