未验证 提交 ea6b7573 编写于 作者: O openharmony_ci 提交者: Gitee

!440 fix: codex

Merge pull request !440 from 熊磊/0317xytcodex
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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),
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册