OSDN Git Service

STPK-1429 Fix Klocwork issue #88846
authorPatrick Porlan <patrick.porlan@intel.com>
Thu, 3 Apr 2014 12:25:46 +0000 (14:25 +0200)
committersuyyala <sridhar.uyyala@intel.com>
Mon, 28 Apr 2014 02:40:39 +0000 (19:40 -0700)
Possible buffer overflow indeed.

Issue STPK-1429

Change-Id: Ic238fc29b212593b1b2fb9385e19f960db817567
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
description.c

index 183c11a..9d675cb 100644 (file)
@@ -19,10 +19,12 @@ char* sensor_get_name (int s)
        if (sensor_info[s].friendly_name[0] == '\0') {
 
                /* If we got a iio device name from sysfs, use it */
-               if (sensor_info[s].internal_name[0])
-                       sprintf(sensor_info[s].friendly_name, "S%d-%s", s,
-                               sensor_info[s].internal_name);
-               else
+               if (sensor_info[s].internal_name[0]) {
+                       snprintf(sensor_info[s].friendly_name,
+                                MAX_NAME_SIZE, "S%d-%s", s,
+                                sensor_info[s].internal_name);
+                       sensor_info[s].friendly_name[MAX_NAME_SIZE-1] = '\0';
+               } else
                        sprintf(sensor_info[s].friendly_name, "S%d", s);
        }