From 72bebcfd1c94737784169b9be2dc790d4b9b84d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Wed, 23 Jul 2025 10:38:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspawn=20=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/common/appspawn_namespace.c | 7 ++++++- standard/appspawn_service.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/common/appspawn_namespace.c b/modules/common/appspawn_namespace.c index e128c4ae..74ae78e1 100644 --- a/modules/common/appspawn_namespace.c +++ b/modules/common/appspawn_namespace.c @@ -127,7 +127,12 @@ APPSPAWN_STATIC pid_t GetPidByName(const char *name) (void)fclose(file); continue; } - buffer[strcspn(buffer, "\n")] = 0; + size_t newline_pos = strcspn(buffer, "\n"); + if (newline_pos < sizeof(buffer) -1) { + buffer[newline_pos] = '\0'; + } else { + buffer[sizeof(buffer) -1] = '\0'; + } if (strcmp(buffer, name) != 0) { (void)fclose(file); continue; diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 49fce144..b53f56d7 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -160,7 +160,7 @@ APPSPAWN_STATIC void WriteSignalInfoToFd(AppSpawnedProcess *appInfo, AppSpawnCon cJSON_AddStringToObject(root, "bundleName", appInfo->name); char *jsonString = cJSON_Print(root); cJSON_Delete(root); - + APPSPAWN_CHECK(jsonString != NULL, return, "jsonString is NULL"); int ret = write(content->signalFd, jsonString, strlen(jsonString) + 1); if (ret < 0) { free(jsonString); -- Gitee