From 25b99d979fcebd77717b88fef01099572999999e Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 25 Nov 2021 14:54:59 +0800 Subject: [PATCH] [TD-11379]: Fix potential memory violation in monitor --- src/plugins/monitor/src/monMain.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index aca4981bd8..ed60ba42ca 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -1221,13 +1221,13 @@ static void monSaveSlowQueryInfo() { if (strcmp(fields[i].name, "query_id") == 0) { has_slowquery = true; charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); - pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen, ", "SQL_STR_FMT, (char *)row[i]); + pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen + 1, ", "SQL_STR_FMT, (char *)row[i]); } else if (strcmp(fields[i].name, "user") == 0) { charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); - pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen, ", "SQL_STR_FMT, (char *)row[i]); + pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen + 1, ", "SQL_STR_FMT, (char *)row[i]); } else if (strcmp(fields[i].name, "qid") == 0) { charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); - pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen, ", "SQL_STR_FMT, (char *)row[i]); + pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen + 1, ", "SQL_STR_FMT, (char *)row[i]); } else if (strcmp(fields[i].name, "created_time") == 0) { int64_t create_time = *(int64_t *)row[i]; create_time = convertTimePrecision(create_time, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO); @@ -1236,10 +1236,10 @@ static void monSaveSlowQueryInfo() { pos += snprintf(sql + pos, SQL_LENGTH, ", %" PRId64 "", *(int64_t *)row[i]); } else if (strcmp(fields[i].name, "ep") == 0) { charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); - pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen, ", "SQL_STR_FMT, (char *)row[i]); + pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen + 1, ", "SQL_STR_FMT, (char *)row[i]); } else if (strcmp(fields[i].name, "sql") == 0) { charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); - pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen + 1, ", "SQL_STR_FMT")", (char *)row[i]); + pos += snprintf(sql + pos, strlen(SQL_STR_FMT) + charLen + 2, ", "SQL_STR_FMT")", (char *)row[i]); } } } -- GitLab