Skip to contentSkip to conversation

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

PATCH Superseded Guenter Roeck 2 participants 2 messages Jun 19, 2012 – Jun 20, 2012 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/4 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.

---
 drivers/hwmon/ntc_thermistor.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ntc_thermistor.c +1 -1
index 6da9696..e46a5b2 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);
+	strncpy(data->name, pdev->id_entry->name, sizeof(data->name) - 1);
 
 	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
#1 lore raw
Quoted 14 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.

---
 drivers/hwmon/ntc_thermistor.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ntc_thermistor.c +0 -0
index 6da9696..e46a5b2 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);
+	strncpy(data->name, pdev->id_entry->name, sizeof(data->name) - 1);
 
 	switch (pdev->id_entry->driver_data) {
 	case TYPE_NCPXXWB473:

Please use strlcpy instead, it's meant exactly for this. strncpy is evil and should be discarded IMHO.

Signature · 6 lines
Jean Delvare

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