diff --git a/process/js_childprocess.cpp b/process/js_childprocess.cpp index 2a92f9a..26785a8 100644 --- a/process/js_childprocess.cpp +++ b/process/js_childprocess.cpp @@ -247,7 +247,7 @@ namespace OHOS::Js_sys_module::Process { if (readSize >= 0) { stdOutInfo->stdData += childStdout; } - if (stdOutInfo->stdData.size() > stdOutInfo->maxBuffSize && *(stdOutInfo->isNeedRun)) { + if (stdOutInfo->stdData.size() > static_cast(stdOutInfo->maxBuffSize) && *(stdOutInfo->isNeedRun)) { if (!kill(stdOutInfo->pid, SIGKILL)) { *(stdOutInfo->isNeedRun) = false; stdOutInfo->stdData = stdOutInfo->stdData.substr(0, stdOutInfo->maxBuffSize); @@ -281,7 +281,7 @@ namespace OHOS::Js_sys_module::Process { if (readSize >= 0) { stdErrInfo->stdData += childStderr; } - if (stdErrInfo->stdData.size() > stdErrInfo->maxBuffSize && *(stdErrInfo->isNeedRun)) { + if (stdErrInfo->stdData.size() > static_cast(stdErrInfo->maxBuffSize) && *(stdErrInfo->isNeedRun)) { if (!kill(stdErrInfo->pid, SIGKILL)) { *(stdErrInfo->isNeedRun) = false; stdErrInfo->stdData = stdErrInfo->stdData.substr(0, stdErrInfo->maxBuffSize); @@ -406,11 +406,17 @@ namespace OHOS::Js_sys_module::Process { std::string ChildProcess::RequireStrValue(const napi_value strValue) { size_t bufferSize = 0; - napi_get_value_string_utf8(env_, strValue, nullptr, 0, &bufferSize); + if (napi_get_value_string_utf8(env_, strValue, nullptr, 0, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get strValue size"); + return nullptr; + } std::string result = ""; result.reserve(bufferSize + 1); result.resize(bufferSize); - napi_get_value_string_utf8(env_, strValue, result.data(), bufferSize + 1, &bufferSize); + if (napi_get_value_string_utf8(env_, strValue, result.data(), bufferSize + 1, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get strValue value"); + return nullptr; + } return result; } diff --git a/process/js_process.cpp b/process/js_process.cpp index d04cd9b..c89d0f9 100644 --- a/process/js_process.cpp +++ b/process/js_process.cpp @@ -128,11 +128,17 @@ namespace OHOS::Js_sys_module::Process { void Process::Chdir(napi_value args) const { size_t prolen = 0; - napi_get_value_string_utf8(env_, args, nullptr, 0, &prolen); + if (napi_get_value_string_utf8(env_, args, nullptr, 0, &prolen) != napi_ok) { + HILOG_ERROR("can not get args size"); + return; + } std::string result = ""; result.reserve(prolen + 1); result.resize(prolen); - napi_get_value_string_utf8(env_, args, result.data(), prolen + 1, &prolen); + if (napi_get_value_string_utf8(env_, args, result.data(), prolen + 1, &prolen) != napi_ok) { + HILOG_ERROR("can not get args value"); + return; + } int proerr = 0; proerr = uv_chdir(result.c_str()); if (proerr) { @@ -244,11 +250,17 @@ namespace OHOS::Js_sys_module::Process { { size_t bufferSize = 0; bool flag = false; - NAPI_CALL(env_, napi_get_value_string_utf8(env_, str, nullptr, 0, &bufferSize)); + if (napi_get_value_string_utf8(env_, str, nullptr, 0, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get str size"); + return nullptr; + } std::string result = ""; result.reserve(bufferSize + 1); result.resize(bufferSize); - napi_get_value_string_utf8(env_, str, result.data(), bufferSize + 1, &bufferSize); + if (napi_get_value_string_utf8(env_, str, result.data(), bufferSize + 1, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get str value"); + return nullptr; + } std::string temp = ""; temp = result; auto iter = eventMap.equal_range(temp); @@ -257,9 +269,9 @@ namespace OHOS::Js_sys_module::Process { iter.first = eventMap.erase(iter.first); flag = true; } - napi_value resultOut = nullptr; - NAPI_CALL(env_, napi_get_boolean(env_, flag, &resultOut)); - return resultOut; + napi_value convertResult = nullptr; + NAPI_CALL(env_, napi_get_boolean(env_, flag, &convertResult)); + return convertResult; } napi_value Process::GetTid() const @@ -320,47 +332,59 @@ namespace OHOS::Js_sys_module::Process { napi_value Process::GetEnvironmentVar(napi_value name) const { - napi_value resultOut = nullptr; + napi_value convertResult = nullptr; char buf[260 * NUM_OF_DATA] = { 0 }; // 260:Only numbers path String size is 260. size_t length = sizeof(buf); size_t bufferSize = 0; - napi_get_value_string_utf8(env_, name, nullptr, 0, &bufferSize); + if (napi_get_value_string_utf8(env_, name, nullptr, 0, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get name size"); + return nullptr; + } std::string result = ""; result.reserve(bufferSize + 1); result.resize(bufferSize); - napi_get_value_string_utf8(env_, name, result.data(), bufferSize + 1, &bufferSize); + if (napi_get_value_string_utf8(env_, name, result.data(), bufferSize + 1, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get name value"); + return nullptr; + } std::string temp = ""; temp = result; auto envNum = uv_os_getenv(temp.c_str(), buf, &length); if (envNum == UV_ENOENT) { - NAPI_CALL(env_, napi_get_undefined(env_, &resultOut)); - return resultOut; + NAPI_CALL(env_, napi_get_undefined(env_, &convertResult)); + return convertResult; } - napi_create_string_utf8(env_, buf, strlen(buf), &resultOut); - return resultOut; + napi_create_string_utf8(env_, buf, strlen(buf), &convertResult); + return convertResult; } napi_value Process::GetUidForName(napi_value name) const { struct passwd *user = nullptr; int32_t uid = 0; - napi_value resultOut = nullptr; + napi_value convertResult = nullptr; size_t bufferSize = 0; - napi_get_value_string_utf8(env_, name, nullptr, 0, &bufferSize); + if (napi_get_value_string_utf8(env_, name, nullptr, 0, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get name size"); + return nullptr; + } std::string result = ""; result.reserve(bufferSize + 1); result.resize(bufferSize); - napi_get_value_string_utf8(env_, name, result.data(), bufferSize + 1, &bufferSize); + if (napi_get_value_string_utf8(env_, name, result.data(), bufferSize + 1, &bufferSize) != napi_ok) { + HILOG_ERROR("can not get name value"); + return nullptr; + } std::string temp = ""; temp = result; user = getpwnam(temp.c_str()); if (user != nullptr) { uid = static_cast(user->pw_uid); - napi_create_int32(env_, uid, &resultOut); - return resultOut; + napi_create_int32(env_, uid, &convertResult); + return convertResult; } - napi_create_int32(env_, (-1), &resultOut); - return resultOut; + napi_create_int32(env_, (-1), &convertResult); + return convertResult; } napi_value Process::GetThreadPriority(napi_value tid) const