From 045e5c5cc38e75b09c37ea8d5492ea7bafd40266 Mon Sep 17 00:00:00 2001 From: Zihao Xue Date: Tue, 11 Jun 2024 20:38:12 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20TEST=5FPWR=5FPROC=5FQueryProcs?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=8C=82=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pwrapic/test/procapitest.c | 14 ++++++++++++++ pwrapis/src/procservice.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pwrapic/test/procapitest.c b/pwrapic/test/procapitest.c index 5a1ef32..acd2881 100644 --- a/pwrapic/test/procapitest.c +++ b/pwrapic/test/procapitest.c @@ -28,6 +28,19 @@ static void TEST_PWR_PROC_QueryProcs(void) printf("PWR_PROC_QueryProcs. ret: %d num:%d\n", ret, num); } +static void TEST_PWR_PROC_QueryProcs_LongKeywords(void) +{ + char keywords[PWR_MAX_STRING_LEN] = "/init|"; + for(int i = 6; i < PWR_MAX_STRING_LEN - 1; ++i) + { + keywords[i] = 'a'; + } + pid_t procs[TEST_MAX_PROC_NUM] = {0}; + uint32_t num = TEST_MAX_PROC_NUM; + int ret = PWR_PROC_QueryProcs(keywords, procs, &num); + printf("PWR_PROC_QueryProcs. ret: %d num:%d\n", ret, num); +} + static void TEST_PWR_PROC_SetAndGetWattState(void) { int state = INVALIDE_STATE; @@ -187,6 +200,7 @@ static void TEST_PWR_PROC_SetServiceState(void) void TEST_PROC_AllFunc(void) { TEST_PWR_PROC_QueryProcs(); + TEST_PWR_PROC_QueryProcs_LongKeywords(); TEST_PWR_PROC_SetAndGetWattState(); TEST_PWR_PROC_SetAndGetWattAttrs(); TEST_PWR_PROC_AddAndDelWattProcs(); diff --git a/pwrapis/src/procservice.c b/pwrapis/src/procservice.c index b1c8f3d..1f8a7c7 100644 --- a/pwrapis/src/procservice.c +++ b/pwrapis/src/procservice.c @@ -163,12 +163,13 @@ static int ModifyServiceState(const PWR_PROC_ServiceState *sState, const char *s static int QueryProcs(const char *keyWords, pid_t procs[], int maxNum, int *procNum) { - char cmd[PWR_MAX_STRING_LEN] = GET_US_PROCS_CMD; + char cmd[PWR_MAX_STRING_LEN + sizeof(QUERY_PROCS_CMD)] = GET_US_PROCS_CMD; if (keyWords && strlen(keyWords) != 0) { if (sprintf(cmd, QUERY_PROCS_CMD, keyWords) < 0) { return PWR_ERR_FILE_SPRINTF_FAILED; } } + Logger(DEBUG, MD_NM_SVR_PROC, "QueryProcs: %s", cmd); FILE *fp = popen(cmd, "r"); if (fp == NULL) { return PWR_ERR_SYS_EXCEPTION; -- Gitee