From e4bf0444ea083c1d40c502ebc5087d7aa7d405e6 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 7 Mar 2024 14:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=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..6f14f82 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) { + 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