fix the out-of-bounds access 61/152461/2
authorSangjin Lee <lsj119@samsung.com>
Tue, 26 Sep 2017 07:42:18 +0000 (16:42 +0900)
committerBoram Park <boram1288.park@samsung.com>
Tue, 26 Sep 2017 23:08:03 +0000 (08:08 +0900)
Change-Id: I2aafc4433ce6c10e5545d8d6d62d22d14a0fde77

src/tbm_bufmgr.c

index ac48c1e..c2c1d53 100644 (file)
@@ -155,18 +155,22 @@ _tbm_flag_to_str(int f)
                int c = 0;
 
                if (f & TBM_BO_SCANOUT)
-                       c = snprintf(&str[c], 255, "SCANOUT");
+                       c += snprintf(&str[c], 255-c, "SCANOUT");
 
                if (f & TBM_BO_NONCACHABLE) {
-                       if (c)
-                               c = snprintf(&str[c], 255, ", ");
-                       c = snprintf(&str[c], 255, "NONCACHABLE,");
+                       if (c >= 0 && c < 255)
+                               c += snprintf(&str[c], 255-c, ", ");
+
+                       if (c >= 0 && c < 255)
+                               c += snprintf(&str[c], 255-c, "NONCACHABLE,");
                }
 
                if (f & TBM_BO_WC) {
-                       if (c)
-                               c = snprintf(&str[c], 255, ", ");
-                       c = snprintf(&str[c], 255, "WC");
+                       if (c >= 0 && c < 255)
+                               c += snprintf(&str[c], 255-c, ", ");
+
+                       if (c >= 0 && c < 255)
+                               c += snprintf(&str[c], 255-c, "WC");
                }
        }