diff --git a/device_info/device_info_kits.cpp b/device_info/device_info_kits.cpp index f5cc59f98789d94a8b898b5f9b3751eba8ce0447..fca182a5782457e10f3267c3621dc8a646ba34c2 100755 --- a/device_info/device_info_kits.cpp +++ b/device_info/device_info_kits.cpp @@ -129,7 +129,8 @@ const char *AclGetSerial(void) OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance(); int ret = instance.GetSerialID(result); if (ret == 0) { - (void)strcpy_s(serialNumber, sizeof(serialNumber), result.c_str()); + ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str()); + DINFO_CHECK(ret == 0, return nullptr, "Failed to copy"); } DINFO_LOGI("GetSerial %s", serialNumber); return serialNumber; diff --git a/interfaces/innerkits/service_control/service_control.c b/interfaces/innerkits/service_control/service_control.c index 0755ea4f8722bf7d8a0f6ccb46b9740c7785828f..1a8396f6ae1f99d7f933d25e6244f984e6ba41a2 100644 --- a/interfaces/innerkits/service_control/service_control.c +++ b/interfaces/innerkits/service_control/service_control.c @@ -221,7 +221,7 @@ int ServiceSetReady(const char *serviceName) BEGET_LOGE("Set param for %s failed.", paramName); return -1; } - BEGET_LOGI("Success set %d read", serviceName); + BEGET_LOGI("Success set %s read", serviceName); return 0; } diff --git a/services/begetctl/main.c b/services/begetctl/main.c index 406346eed7148ff3d60f375503196aef055083a5..c062ab84f243e92577963bc916351c7bc1f67731 100755 --- a/services/begetctl/main.c +++ b/services/begetctl/main.c @@ -65,7 +65,9 @@ int main(int argc, char *argv[]) args = argv + 1; } if (number >= 1 && strcmp(args[0], "devctl") == 0) { - (void)memcpy_s(args[0], strlen(args[0]), "reboot", strlen("reboot")); + if (memcpy_s(args[0], strlen(args[0]), "reboot", strlen("reboot")) != 0) { + printf("Failed to copy\n"); + } } SetInitLogLevel(0); BShellParamCmdRegister(g_handle, 0); diff --git a/services/begetctl/param_cmd.c b/services/begetctl/param_cmd.c index 0764d3738e8ffca0df53da50982be1b48daf7e78..07d0f743de73ed81c7b39e92c3f912b759bb1ceb 100755 --- a/services/begetctl/param_cmd.c +++ b/services/begetctl/param_cmd.c @@ -91,6 +91,7 @@ static char *GetRealParameter(BShellHandle shell, const char *name, char *buffer } else { realLen = sprintf_s(buffer, buffSize, "%s", name); } + BSH_CHECK(realLen > 0, return NULL, "Failed to format buffer"); buffer[realLen] = '\0'; BSH_LOGV("GetRealParameter current %s input %s real %s", current, name, buffer); return buffer; diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index bdb7079f3f0657a9e607807a1392af967eebd5ea..450c35171d650547230f7dfb03ecfce94f9b6bd9 100755 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -229,7 +229,10 @@ static void PublishHoldFds(Service *service) fdBuffer[pos - 1] = '\0'; // Remove last ' ' INIT_LOGI("fd buffer: [%s]", fdBuffer); char envName[MAX_BUFFER_LEN] = {}; - (void)snprintf_s(envName, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, ENV_FD_HOLD_PREFIX"%s", service->name); + if (snprintf_s(envName, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, ENV_FD_HOLD_PREFIX"%s", service->name) < 0) { + INIT_LOGE("snprintf_s failed err=%d", errno); + return; + } if (setenv(envName, fdBuffer, 1) < 0) { INIT_LOGE("Failed to set env %s", envName); } diff --git a/services/init/standard/fd_holder_service.c b/services/init/standard/fd_holder_service.c index 9f46a3ab9e07e7b927bb296c1893e31b2dc82709..ae0856e343459cc516508cda6daad84cc33b4aad 100644 --- a/services/init/standard/fd_holder_service.c +++ b/services/init/standard/fd_holder_service.c @@ -62,12 +62,17 @@ static int HandlerHoldFds(Service *service, int *fds, size_t fdCount, const char static void SendErrorInfo(int sock, const char *errInfo, const char *serviceName) { + int ret = 0; char errBuffer[MAX_FD_HOLDER_BUFFER] = {}; if (UNLIKELY(errInfo == NULL)) { // Should not happen. char *defaultError = "Unknonw error"; - (void)strncpy_s(errBuffer, MAX_FD_HOLDER_BUFFER, defaultError, strlen(defaultError)); + ret = strncpy_s(errBuffer, MAX_FD_HOLDER_BUFFER, defaultError, strlen(defaultError)); } else { - (void)strncpy_s(errBuffer, MAX_FD_HOLDER_BUFFER, errInfo, strlen(errInfo)); + ret = strncpy_s(errBuffer, MAX_FD_HOLDER_BUFFER, errInfo, strlen(errInfo)); + } + if (ret != 0) { + INIT_LOGE("Failed to copy, err = %d", errno); + return; } struct iovec iovec = { @@ -96,7 +101,10 @@ static void SendFdsInfo(int sock, Service *service) return; } char sendBuffer[MAX_FD_HOLDER_BUFFER] = {}; - (void)strncpy_s(sendBuffer, MAX_FD_HOLDER_BUFFER, "send done", strlen("send done")); + if (strncpy_s(sendBuffer, MAX_FD_HOLDER_BUFFER, "send done", strlen("send done")) != 0) { + INIT_LOGE("Failed to copy, err = %d", errno); + return; + } struct iovec iovec = { .iov_base = sendBuffer, .iov_len = strlen(sendBuffer), diff --git a/services/loopevent/socket/le_socket.c b/services/loopevent/socket/le_socket.c index 80a039f3ee0dcc974bcd87e0675e22fd4646c11f..78d588225c23c5e402227afbe3322e4584f15ca0 100755 --- a/services/loopevent/socket/le_socket.c +++ b/services/loopevent/socket/le_socket.c @@ -36,11 +36,15 @@ static int CreatePipeServerSocket_(const char *server, int maxClient) unlink(server); struct sockaddr_un serverAddr; - memset_s(&serverAddr, sizeof(serverAddr), 0, sizeof(serverAddr)); + int ret = memset_s(&serverAddr, sizeof(serverAddr), 0, sizeof(serverAddr)); + LE_CHECK(ret == 0, close(listenfd); + return ret, "Failed to memory set. error: %s", strerror(errno)); serverAddr.sun_family = AF_UNIX; - strcpy_s(serverAddr.sun_path, sizeof(serverAddr.sun_path), server); + ret = strcpy_s(serverAddr.sun_path, sizeof(serverAddr.sun_path), server); + LE_CHECK(ret == 0, close(listenfd); + return ret, "Failed to copy. error: %s", strerror(errno)); uint32_t size = offsetof(struct sockaddr_un, sun_path) + strlen(server); - int ret = bind(listenfd, (struct sockaddr *)&serverAddr, size); + ret = bind(listenfd, (struct sockaddr *)&serverAddr, size); LE_CHECK(ret >= 0, close(listenfd); return ret, "Failed to bind socket. error: %s", strerror(errno)); @@ -91,13 +95,14 @@ static int CreatePipeSocket_(const char *server) LE_STATUS GetSockaddrFromServer_(const char *server, struct sockaddr_in *addr) { - memset_s(addr, sizeof(struct sockaddr_in), 0, sizeof(struct sockaddr_in)); + int ret = memset_s(addr, sizeof(struct sockaddr_in), 0, sizeof(struct sockaddr_in)); + LE_CHECK(ret == 0, return ret, "Failed to memory set. error: %s", strerror(errno)); addr->sin_family = AF_INET; const char *portStr = strstr(server, ":"); LE_CHECK(portStr != NULL, return LE_FAILURE, "Failed to get addr %s", server); uint16_t port = atoi(portStr + 1); addr->sin_port = htons(port); - int ret = inet_pton(AF_INET, server, &addr->sin_addr); + ret = inet_pton(AF_INET, server, &addr->sin_addr); LE_CHECK(ret >= 0, return LE_FAILURE, "Failed to inet_pton addr %s", server); return LE_SUCCESS; }