Skip to contentSkip to conversation

firmware: ti_sci: fix strncat length check

PATCH In review Arnd Bergmann 2 participants 2 messages Jan 11, 2017 Texas instruments' system control interface (TISCI) protocol driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: ti_sci: fix strncat length check

gcc-7 notices that the length we pass to strncat is wrong:

drivers/firmware/ti_sci.c: In function 'ti_sci_probe':
drivers/firmware/ti_sci.c:204:32: error: specified bound 50 equals the size of the destination [-Werror=stringop-overflow=]

Instead of the total length, we must pass the length of the remaining space here.

Fixes aa276781a64a ("firmware: Add basic support for TI System Control Interface (TI-SCI) protocol")
---
 drivers/firmware/ti_sci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/ti_sci.c +2 -1
index 874ff32db366..00cfed3c3e1a 100644
@@ -202,7 +202,8 @@ static int ti_sci_debugfs_create(struct platform_device *pdev,
 	info->debug_buffer[info->debug_region_size] = 0;
 
 	info->d = debugfs_create_file(strncat(debug_name, dev_name(dev),
-					      sizeof(debug_name)),
+					      sizeof(debug_name) -
+					      sizeof("ti_sci_debug@")),
 				      0444, NULL, info, &ti_sci_debug_fops);
 	if (IS_ERR(info->d))
 		return PTR_ERR(info->d);
Signature · 1 line
2.9.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Arnd Bergmann

gcc-7 notices that the length we pass to strncat is wrong:

drivers/firmware/ti_sci.c: In function 'ti_sci_probe':
drivers/firmware/ti_sci.c:204:32: error: specified bound 50 equals the size of the destination [-Werror=stringop-overflow=]

Instead of the total length, we must pass the length of the remaining space here.

Fixes aa276781a64a ("firmware: Add basic support for TI System Control Interface (TI-SCI) protocol")
---
 drivers/firmware/ti_sci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/ti_sci.c +0 -0
index 874ff32db366..00cfed3c3e1a 100644

drivers/firmware/ti_sci.c static int ti_sci_debugfs_create(struct platform_device *pdev, · line 209

Quoted 9 lines
drivers/firmware/ti_sci.c +2 -1
@@ -202,7 +202,8 @@ static int ti_sci_debugfs_create(struct platform_device *pdev,
        info->debug_buffer[info->debug_region_size] = 0;
 
        info->d = debugfs_create_file(strncat(debug_name, dev_name(dev),
-                                             sizeof(debug_name)),
+                                             sizeof(debug_name) -
+                                             sizeof("ti_sci_debug@")),
                                      0444, NULL, info, &ti_sci_debug_fops);
        if (IS_ERR(info->d))
                return PTR_ERR(info->d);

Aargh.. thanks.... Santosh: if you could pick this up.. using strlen(debug_name) might be an overkill here.

---
Regards,
Nishanth Menon