From 96a0de4824a1f4df75ad2c0c54ae1ded73990785 Mon Sep 17 00:00:00 2001 From: heppen Date: Thu, 30 May 2024 21:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(socket):=20memcpy=20null=20p?= =?UTF-8?q?ointer,=20array=20out=20of=20bounds,=20struct=20align?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/inc/pwrdata.h | 2 +- pwrapic/src/sockclient.c | 4 +++- pwrapis/src/cpuservice.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/inc/pwrdata.h b/common/inc/pwrdata.h index 0dfe14b..9af8943 100644 --- a/common/inc/pwrdata.h +++ b/common/inc/pwrdata.h @@ -27,7 +27,7 @@ #define PWR_MAX_NUMA_NODE_NUM 128 #define PWR_MAX_GOV_NUM 16 #define PWR_MAX_STRING_LEN 1000 -#define PWR_MAX_TIME_LEN 25 +#define PWR_MAX_TIME_LEN 32 #define PWR_MAX_DC_INTERVAL 100000000 #define PWR_MIN_DC_INTERVAL 1000 #define PWR_CPU_USAGE_COLUMN 8 diff --git a/pwrapic/src/sockclient.c b/pwrapic/src/sockclient.c index 3007cd6..9601248 100644 --- a/pwrapic/src/sockclient.c +++ b/pwrapic/src/sockclient.c @@ -271,7 +271,9 @@ static void SendMsgToSocket(void) if (len <= MAX_DATA_SIZE) { memcpy(data, msg, sizeof(PwrMsg)); - memcpy(data + sizeof(PwrMsg), msg->data, msg->head.dataLen); + if (msg->data && msg->head.dataLen > 0) { + memcpy(data + sizeof(PwrMsg), msg->data, msg->head.dataLen); + } WriteMsg(data, len); } else { memcpy(data, msg, sizeof(PwrMsg)); diff --git a/pwrapis/src/cpuservice.c b/pwrapis/src/cpuservice.c index 2d4d21a..a3d5b33 100644 --- a/pwrapis/src/cpuservice.c +++ b/pwrapis/src/cpuservice.c @@ -160,7 +160,7 @@ static int UsageToLong(char *buf, unsigned long paras[], int line) int j = 0; int k; char temp[PWR_MAX_STRING_LEN]; - while (i <= PWR_CPU_USAGE_COLUMN) { + while (i < PWR_CPU_USAGE_COLUMN) { bzero(temp, sizeof(temp)); k = 0; while (buf[j] != ' ') { -- Gitee