From 565d1f408cdd8f0bd1ed2e7937aad0f4fda5d431 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 22 May 2024 13:26:49 +0800 Subject: [PATCH] fix(stream): adjust buf size, and avoid overflow --- source/dnode/mnode/impl/src/mndStream.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index d65d708bb8..98f438bf88 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -1620,10 +1620,10 @@ static int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SS colDataSetVal(pColInfo, numOfRows, (const char *)&pe->stage, false); // input queue - char vbuf[40] = {0}; - char buf[40] = {0}; + char vbuf[37] = {0}; + char buf[35] = {0}; const char *queueInfoStr = "%4.2f MiB (%6.2f%)"; - sprintf(buf, queueInfoStr, pe->inputQUsed, pe->inputRate); + snprintf(buf, tListLen(buf), queueInfoStr, pe->inputQUsed, pe->inputRate); STR_TO_VARSTR(vbuf, buf); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1633,9 +1633,9 @@ static int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SS const char* formatTotalMb = "%7.2f MiB"; const char* formatTotalGb = "%7.2f GiB"; if (pe->procsTotal < 1024) { - sprintf(buf, formatTotalMb, pe->procsTotal); + snprintf(buf, tListLen(buf), formatTotalMb, pe->procsTotal); } else { - sprintf(buf, formatTotalGb, pe->procsTotal / 1024); + snprintf(buf, tListLen(buf), formatTotalGb, pe->procsTotal / 1024); } memset(vbuf, 0, tListLen(vbuf)); @@ -1648,9 +1648,9 @@ static int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SS const char* formatKb = "%7.2f KiB/s"; const char* formatMb = "%7.2f MiB/s"; if (pe->procsThroughput < 1024) { - sprintf(buf, formatKb, pe->procsThroughput); + snprintf(buf, tListLen(buf), formatKb, pe->procsThroughput); } else { - sprintf(buf, formatMb, pe->procsThroughput / 1024); + snprintf(buf, tListLen(buf), formatMb, pe->procsThroughput / 1024); } memset(vbuf, 0, tListLen(vbuf)); @@ -1679,9 +1679,9 @@ static int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SS colDataSetNULL(pColInfo, numOfRows); } else { if (pe->outputThroughput < 1024) { - sprintf(buf, formatKb, pe->outputThroughput); + snprintf(buf, tListLen(buf), formatKb, pe->outputThroughput); } else { - sprintf(buf, formatMb, pe->outputThroughput / 1024); + snprintf(buf, tListLen(buf), formatMb, pe->outputThroughput / 1024); } memset(vbuf, 0, tListLen(vbuf));