From a19c61a9b7fcd8f58b8e862f8a3f7ccf11ffdcc5 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 7 Mar 2024 11:16:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- frameworks/config_policy/src/config_policy_utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index 54d8ca3..c618837 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -97,7 +97,7 @@ static char *CustGetSystemParam(const char *name) char *value = NULL; unsigned int len = 0; - if (SystemGetParameter(name, NULL, &len) != 0 || len == 0) { + if (SystemGetParameter(name, NULL, &len) != 0 || len <= 0 || len > PARAM_CONST_VALUE_LEN_MAX) { return NULL; } value = (char *)calloc(len, sizeof(char)); @@ -290,8 +290,11 @@ static char *TrimInplace(char *str, bool moveToStart) static bool EnsureHolderSpace(StringHolder *holder, size_t leastSize) { + if (holder == NULL || s == NULL) { + return false; + } if (holder->size < leastSize) { - size_t allocSize = Max(leastSize * 2, MIN_APPEND_LEN); + size_t allocSize = Min(Max(leastSize * 2, MIN_APPEND_LEN), PARAM_CONST_VALUE_LEN_MAX); char *newPtr = (char *)calloc(allocSize, sizeof(char)); if (newPtr == NULL) { allocSize = leastSize; @@ -313,6 +316,9 @@ static bool EnsureHolderSpace(StringHolder *holder, size_t leastSize) static bool AppendStr(StringHolder *holder, const char *s) { + if (holder == NULL || s == NULL) { + return false; + } size_t leastSize = holder->strLen + strlen(s) + 1; if (!EnsureHolderSpace(holder, leastSize)) { return false; -- Gitee From 475ee2950cc30e3947d7cca15b26db8cdd640a22 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 7 Mar 2024 11:36:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- frameworks/config_policy/src/config_policy_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index c618837..6f14f82 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -290,7 +290,7 @@ static char *TrimInplace(char *str, bool moveToStart) static bool EnsureHolderSpace(StringHolder *holder, size_t leastSize) { - if (holder == NULL || s == NULL) { + if (holder == NULL) { return false; } if (holder->size < leastSize) { -- Gitee