prevent buffer overflow at memcpy 61/140161/3 accepted/tizen/4.0/unified/20170816.013042 accepted/tizen/4.0/unified/20170829.015805 accepted/tizen/unified/20170725.173452 submit/tizen/20170724.065948 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170828.100004 submit/tizen_4.0/20170828.110004
authorDongsun Lee <ds73.lee@samsung.com>
Mon, 24 Jul 2017 05:01:33 +0000 (14:01 +0900)
committerDongsun Lee <ds73.lee@samsung.com>
Mon, 24 Jul 2017 06:56:08 +0000 (15:56 +0900)
Change-Id: I956e8f89b0fa422c3a1eab006ade07282bb7646a
Signed-off-by: Dongsun Lee <ds73.lee@samsung.com>
service/drm-tapps.cpp

index 93eec5e..ad840ef 100644 (file)
 #ifdef __DRM_TAPPS_API_TIME_PROFILING__
 #include <sys/time.h>
 
+#define MAX_FUNCTION_NAME_LENGTH 256
+
 class DrmTappsProf {
 public:
        DrmTappsProf(const char *function);
        ~DrmTappsProf();
        struct timeval TappsStartTv;
        struct timeval TappsStopTv;
-       char TappsfunNane[256];
+       char TappsfunName[MAX_FUNCTION_NAME_LENGTH];
 };
 
 DrmTappsProf::DrmTappsProf(const char *function)
 {
-       memcpy(TappsfunNane, function, strlen(function));
+       size_t fun_len = strlen(function);
+       size_t cpy_len = (fun_len < MAX_FUNCTION_NAME_LENGTH) ? fun_len : MAX_FUNCTION_NAME_LENGTH - 1;
+       memcpy(TappsfunName, function, cpy_len);
+       TappsfunName[cpy_len] = '\0';
        gettimeofday(&TappsStartTv, NULL);
        DRM_TAPPS_EXCEPTION("[DRM-TIZEN-PERF]START:SEC=%ld, USEC=%ld for [%s]",
                                                (long int)(TappsStartTv.tv_sec) , (long int)(TappsStartTv.tv_usec), function);
+
 }
 
 DrmTappsProf::~DrmTappsProf()
 {
        gettimeofday(&TappsStopTv, NULL);
        DRM_TAPPS_EXCEPTION("[DRM-TIZEN-PERF] STOP:SEC=%ld, USEC=%ld for [%s]",
-                                               (long int)(TappsStopTv.tv_sec), (long int)(TappsStopTv.tv_usec), TappsfunNane);
+                                               (long int)(TappsStopTv.tv_sec), (long int)(TappsStopTv.tv_usec), TappsfunName);
        DRM_TAPPS_EXCEPTION("[DRM-TIZEN-PERF]TOTAL_DIFFF  : USEC=%ld for [%s]",
                                                ((long int)(TappsStopTv.tv_sec - TappsStartTv.tv_sec) * (1000000) + (long int)(
-                                                        TappsStopTv.tv_usec - TappsStartTv.tv_usec)), TappsfunNane);
+                                                        TappsStopTv.tv_usec - TappsStartTv.tv_usec)), TappsfunName);
 }
 
-#define DRM_TAPPS_API_TIME() DrmTappsProf DrmTappsObj(__func__);
+#define DRM_TAPPS_API_TIME() DrmTappsProf(__func__);
 #else
 #define DRM_TAPPS_API_TIME()
 #endif /* __DRM_TAPPS_API_TIME_PROFILING__ */