Skip to contentSkip to conversation

hwmon: (ntc_thermistor) Ensure that data->name string is terminated

PATCH In review Guenter Roeck 2 participants 2 messages Jun 20, 2012 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: (ntc_thermistor) Ensure that data->name string is terminated

Fix Coverity warning: Calling strncpy with a maximum size argument of 20 bytes on destination array "data->name" of size 20 bytes might leave the destination string unterminated.

Fix by replacing strncpy() with strlcpy() and by using sizeof() to determine the maximum string length.

---
v2: Use strlcpy instead of strncpy

 drivers/hwmon/ntc_thermistor.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ntc_thermistor.c +1 -1
index 6da9696..74a6c58 100644
@@ -351,7 +351,7 @@ static int __devinit ntc_thermistor_probe(struct platform_device *pdev)
 
 	data->dev = &pdev->dev;
 	data->pdata = pdata;
-	strncpy(data->name, pdev->id_entry->name, PLATFORM_NAME_SIZE);
+	strlcpy(data->name, pdev->id_entry->name, sizeof(data->name));
 
 	switch (pdev->id_entry->driver_data) {
 	case TYPE_NCPXXWB473:
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v2 1/1
#1 lore raw
Quoted 19 lines · Guenter Roeck

Fix Coverity warning: Calling strncpy with a maximum size argument of 20 bytes on destination array "data->name" of size 20 bytes might leave the destination string unterminated.

Fix by replacing strncpy() with strlcpy() and by using sizeof() to determine the maximum string length.

---
v2: Use strlcpy instead of strncpy

 drivers/hwmon/ntc_thermistor.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ntc_thermistor.c +0 -0
index 6da9696..74a6c58 100644

drivers/hwmon/ntc_thermistor.c static int __devinit ntc_thermistor_probe(struct platform_device *pdev) · line 357

Quoted 8 lines
drivers/hwmon/ntc_thermistor.c +1 -1
@@ -351,7 +351,7 @@ static int __devinit ntc_thermistor_probe(struct platform_device *pdev)
 
 	data->dev = &pdev->dev;
 	data->pdata = pdata;
-	strncpy(data->name, pdev->id_entry->name, PLATFORM_NAME_SIZE);
+	strlcpy(data->name, pdev->id_entry->name, sizeof(data->name));
 
 	switch (pdev->id_entry->driver_data) {
 	case TYPE_NCPXXWB473:
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors