diff --git a/dfx/native_module_dfx.cpp b/dfx/native_module_dfx.cpp index 3f73c39..5ab7e24 100644 --- a/dfx/native_module_dfx.cpp +++ b/dfx/native_module_dfx.cpp @@ -16,6 +16,7 @@ #include "napi/native_api.h" #include "native_engine.h" #include "napi/native_node_api.h" +#include "securec.h" #include "utils/log.h" namespace OHOS::Js_sys_module::Dfx { @@ -53,9 +54,14 @@ namespace OHOS::Js_sys_module::Dfx { { napi_value result = nullptr; NativeEngine *engine = reinterpret_cast(env); - std::string stackTraceResult = engine->BuildNativeAndJsBackStackTrace(); + std::string stackTraceResult = ""; + bool temp = engine->BuildNativeAndJsBackStackTrace(stackTraceResult); NAPI_CALL(env, napi_create_string_utf8(env, stackTraceResult.c_str(), stackTraceResult.size(), &result)); - return result; + if (temp) { + return result; + } else { + return nullptr; + } } static napi_value StartHeapTracking(napi_env env, napi_callback_info info) @@ -66,11 +72,21 @@ namespace OHOS::Js_sys_module::Dfx { NAPI_ASSERT(env, argc <= requireArgc, "Wrong number of arguments"); napi_value *argv = nullptr; argv = new napi_value[argc]; + NAPI_ASSERT(env, argc > 0, "argc == 0"); + argv = new napi_value[argc + 1]; + if (memset_s(argv, argc + 1, 0, argc + 1) != 0) { + HILOG_ERROR("argv memset error"); + delete []argv; + argv = nullptr; + return nullptr; + } napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); double timeInterval = 0; napi_get_value_double(env, argv[0], &timeInterval); bool isVmMode = true; napi_get_value_bool(env, argv[1], &isVmMode); + delete []argv; + argv = nullptr; NativeEngine *engine = reinterpret_cast(env); auto startResult = engine->StartHeapTracking(timeInterval, isVmMode); napi_value result = nullptr; diff --git a/process/js_childprocess.cpp b/process/js_childprocess.cpp index f76197a..205cc11 100644 --- a/process/js_childprocess.cpp +++ b/process/js_childprocess.cpp @@ -70,12 +70,12 @@ namespace OHOS::Js_sys_module::Process { { int ret = pipe(stdOutFd_); if (ret < 0) { - HILOG_ERROR("pipe1 faile %{public}d", errno); + HILOG_ERROR("pipe1 failed %{public}d", errno); return; } ret = pipe(stdErrFd_); if (ret < 0) { - HILOG_ERROR("pipe2 faile %{public}d", errno); + HILOG_ERROR("pipe2 failed %{public}d", errno); return; } std::string strCommnd = RequireStrValue(command); diff --git a/process/js_process.cpp b/process/js_process.cpp index f1a162e..11025dc 100644 --- a/process/js_process.cpp +++ b/process/js_process.cpp @@ -92,16 +92,16 @@ namespace OHOS::Js_sys_module::Process { if (std::find(pgrous.begin(), pgrous.end(), proegid) == pgrous.end()) { pgrous.push_back(proegid); } - std::vector arry; + std::vector array; for (auto iter = pgrous.begin(); iter != pgrous.end(); iter++) { auto recive = static_cast(*iter); - arry.push_back(recive); + array.push_back(recive); } NAPI_CALL(env_, napi_create_array(env_, &result)); - size_t len = arry.size(); + size_t len = array.size(); for (size_t i = 0; i < len; i++) { napi_value numvalue = nullptr; - NAPI_CALL(env_, napi_create_uint32(env_, arry[i], &numvalue)); + NAPI_CALL(env_, napi_create_uint32(env_, array[i], &numvalue)); NAPI_CALL(env_, napi_set_element(env_, result, i, numvalue)); } return result; @@ -290,7 +290,7 @@ namespace OHOS::Js_sys_module::Process { auto prouid = static_cast(getuid()); auto uid = prouid % PER_USER_RANGE; if ((uid >= 99000 && uid <= 99999) || // 99999:Only isolateuid numbers between 99000 and 99999. - (uid >= 9000 && uid <= 98999)) { // 98999:Only appuid numbers betweeen 9000 and 98999. + (uid >= 9000 && uid <= 98999)) { // 98999:Only appuid numbers between 9000 and 98999. NAPI_CALL(env_, napi_get_boolean(env_, flag, &result)); return result; }