From f9ed8c9b1e49e8a301af496dac922bc6c40376a8 Mon Sep 17 00:00:00 2001 From: Sangjin Lee Date: Tue, 26 Sep 2017 16:42:18 +0900 Subject: [PATCH] fix the out-of-bounds access Change-Id: I2aafc4433ce6c10e5545d8d6d62d22d14a0fde77 --- src/tbm_bufmgr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index ac48c1e..c2c1d53 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -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"); } } -- 2.7.4