diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..3babb71341ee7d8ebfeb073dafb672fee0f0e384 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,67 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "condition_variable": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "shared_mutex": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/frameworks/hilog_ndk/BUILD.gn b/frameworks/hilog_ndk/BUILD.gn index ff22b32a9e434101e75abcec58431d93492974a5..d69f53fdf7c4980f70785ea5c1e09f026e5cd1a6 100644 --- a/frameworks/hilog_ndk/BUILD.gn +++ b/frameworks/hilog_ndk/BUILD.gn @@ -14,6 +14,7 @@ import("//build/ohos.gni") ohos_shared_library("hilog_ndk") { + branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index c8bbd92fe0d1102891074895640425dfe01bc0be..e201517ba30e8e78157932a0c57d5bfc88bfaba9 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -41,6 +41,12 @@ config("libhilog_config") { template("libhilog_source") { forward_variables_from(invoker, "*") ohos_source_set(target_name) { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } if (platform != "windows" && platform != "mac" && platform != "linux") { param_sources = [ "$param_root/properties.cpp" ] ioctl_sources = [ "$ioctl_root/log_ioctl.cpp" ] diff --git a/interfaces/js/kits/napi/src/common/napi/n_val.cpp b/interfaces/js/kits/napi/src/common/napi/n_val.cpp index e97f317c6a255319ada5f52a7504cf3c971eaea0..4622dd2c8ed2f2707b8b21f111aec8e51866d8ba 100644 --- a/interfaces/js/kits/napi/src/common/napi/n_val.cpp +++ b/interfaces/js/kits/napi/src/common/napi/n_val.cpp @@ -30,13 +30,18 @@ NVal::operator bool() const } bool NVal::TypeIs(napi_valuetype expType) const +{ + return ValueTypeIs(val_, expType); +} + +bool NVal::ValueTypeIs(napi_value value, napi_valuetype expType) const { if (!*this) { return false; } napi_valuetype valueType; - napi_typeof(env_, val_, &valueType); + napi_typeof(env_, value, &valueType); if (expType != valueType) { return false; @@ -173,6 +178,47 @@ tuple NVal::ToTypedArrayInfo return make_tuple(status == napi_ok, data, length, byte_offset, type); } +string NVal::GetPrintString(napi_value value) const +{ + string str; + if(!ValueTypeIs(value, napi_string)) { + napi_value strValue = nullptr; + if (napi_coerce_to_string(env_, value, &strValue) != napi_ok) { + return str; + } + value = strValue; + } + napi_get_print_string(env_, value, str); + return str; +} + +tuple NVal::GetValObjectAsStr() const +{ + napi_value globalValue = nullptr; + auto fail = make_tuple(false, ""); + napi_status status = napi_get_global(env_, &globalValue); + if (status != napi_ok) { + return fail; + } + napi_value jsonValue = nullptr; + status = napi_get_named_property(env_, globalValue, "JSON", &jsonValue); + if (status != napi_ok) { + return fail; + } + napi_value stringifyValue = nullptr; + status = napi_get_named_property(env_, jsonValue, "stringify", &stringifyValue); + if (status != napi_ok) { + return fail; + } + napi_value transValue = nullptr; + status = napi_call_function(env_, jsonValue, stringifyValue, 1, &val_, &transValue); + if (status != napi_ok || transValue == nullptr) { + return fail; + } + string content = GetPrintString(transValue); + return make_tuple(true, content); +} + bool NVal::HasProp(string propName) const { bool res = false; diff --git a/interfaces/js/kits/napi/src/common/napi/n_val.h b/interfaces/js/kits/napi/src/common/napi/n_val.h index e2ed44dceb44b461742287e7b1a19856041f259d..2a0e1abe99e4f98a2b1aee93fde7ea852fbadd66 100644 --- a/interfaces/js/kits/napi/src/common/napi/n_val.h +++ b/interfaces/js/kits/napi/src/common/napi/n_val.h @@ -41,6 +41,8 @@ public: bool TypeIs(napi_valuetype expType) const; + bool ValueTypeIs(napi_value value, napi_valuetype expType) const; + /* SHOULD ONLY BE USED FOR EXPECTED TYPE */ std::tuple, size_t> ToUTF8String() const; @@ -68,6 +70,8 @@ public: std::tuple ToTypedArrayInfo() const; + std::tuple GetValObjectAsStr() const; + /* Static helpers to create js objects */ static NVal CreateUndefined(napi_env env); @@ -109,6 +113,8 @@ public: static inline napi_property_descriptor DeclareNapiGetterSetter(const char *name, napi_callback getter, napi_callback setter); +private: + std::string GetPrintString(napi_value value) const; }; } // namespace HiviewDFX } // namespace OHOS diff --git a/interfaces/js/kits/napi/src/common/napi/uni_header.h b/interfaces/js/kits/napi/src/common/napi/uni_header.h index d000d78443d4388ff6bfe2e2eb5c94dbfba671ce..5de61d663fd45789f0791aceee036f7589fda8b0 100644 --- a/interfaces/js/kits/napi/src/common/napi/uni_header.h +++ b/interfaces/js/kits/napi/src/common/napi/uni_header.h @@ -15,10 +15,6 @@ #ifndef INTERFACES_JS_KITS_NAPI_SRC_COMMON_NAPI_UNI_HEADER_H #define INTERFACES_JS_KITS_NAPI_SRC_COMMON_NAPI_UNI_HEADER_H -#pragma once - -#include -#else #include "napi/native_api.h" #include "napi/native_node_api.h" diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp index 4e5ca26dc7d500b99036fbb29786792bca41c0af..4de4ba4ebb62a569f832449050eb28fedbde7ffb 100644 --- a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp @@ -95,7 +95,8 @@ void ParseLogContent(string& formatStr, vector& params, string& logCo break; case 'O': case 'o': - if (params[count].type == napi_object) { + if (params[count].type == napi_object || params[count].type == napi_function || + params[count].type == napi_undefined || params[count].type == napi_null) { ret += (priv && showPriv) ? PRIV_STR : params[count].val; } count++; @@ -223,8 +224,8 @@ napi_value HilogNapiBase::parseNapiValue(napi_env env, napi_callback_info info, if (typeStatus != napi_ok) { return nullptr; } - if (type == napi_number || type == napi_bigint || type == napi_object || - type == napi_undefined || type == napi_boolean || type == napi_null) { + if (type == napi_number || type == napi_bigint || type == napi_undefined || + type == napi_boolean || type == napi_null) { napi_value elmString; napi_status objectStatus = napi_coerce_to_string(env, element, &elmString); if (objectStatus != napi_ok) { @@ -234,6 +235,8 @@ napi_value HilogNapiBase::parseNapiValue(napi_env env, napi_callback_info info, if (!succ) { return nullptr; } + } else if (type == napi_object || type == napi_function) { + tie(succ, res.val) = NVal(env, element).GetValObjectAsStr(); } else if (type == napi_string) { tie(succ, name, ignore) = NVal(env, element).ToUTF8String(); if (!succ) { diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index 26c638ba7d055132617bde8cb9ff983aed62cf08..8c43d64c7b31362a4dd531b5daab86a461ee3f37 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -49,6 +49,7 @@ if (is_mingw || is_mac || is_linux || is_ohos) { "system", "updater", ] + branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true @@ -73,6 +74,7 @@ template("libhilog") { } } else { ohos_shared_library(target_name) { + branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true diff --git a/services/hilogd/BUILD.gn b/services/hilogd/BUILD.gn index 9a5bbede8c74551dc5c85367fa1cc110264352be..5ad2377ea6fe51bec83ab8d4735bd46b0930d419 100644 --- a/services/hilogd/BUILD.gn +++ b/services/hilogd/BUILD.gn @@ -20,6 +20,12 @@ config("hilogd_config") { } ohos_executable("hilogd") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } sources = [ "cmd_executor.cpp", "flow_control.cpp", diff --git a/services/hilogtool/BUILD.gn b/services/hilogtool/BUILD.gn index aa7ea15b765fc34ae7f836e30413358aacdee476..b142f967760b5f9b053c30e48c839c8758028a78 100644 --- a/services/hilogtool/BUILD.gn +++ b/services/hilogtool/BUILD.gn @@ -20,6 +20,12 @@ config("hilog_config") { } ohos_executable("hilog") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } sources = [ "log_display.cpp", "main.cpp", diff --git a/test/moduletest/common/hilog_base_ndk_test.cpp b/test/moduletest/common/hilog_base_ndk_test.cpp index 9f91a7e315579cdd2c676774bd4b50970793bd4c..ce6b83e5698222a5f9a661804309aa8d55151fd3 100644 --- a/test/moduletest/common/hilog_base_ndk_test.cpp +++ b/test/moduletest/common/hilog_base_ndk_test.cpp @@ -146,57 +146,6 @@ bool CheckHiLogPrint(char *needToMatch) } return ret; } - -// Detects how many FDs are linked to hilogd. -int CheckHiLogdLinked() -{ - #define PROC_PATH_LENGTH (64) - int result = 0; - char procPath[PROC_PATH_LENGTH]; - int res = snprintf_s(procPath, PROC_PATH_LENGTH, PROC_PATH_LENGTH - 1, "/proc/%d/fd", getpid()); - if (res == NEGATIVE_ONE) { - printf("CheckHiLogdLinked getpid snprintf_s failed\n"); - return 0; - } - DIR *dir = opendir(procPath); - if (dir == nullptr) { - return result; - } - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - if (entry->d_type != DT_LNK) { - continue; - } - char fdPath[128]; - res = snprintf_s(fdPath, sizeof(fdPath), sizeof(fdPath) - 1, "%s/%s", procPath, entry->d_name); - if (res == NEGATIVE_ONE) { - printf("CheckHiLogdLinked fd search snprintf_s failed\n"); - return 0; - } - - char target[256]; - ssize_t len = readlink(fdPath, target, sizeof(target) - 1); - if (len == -1) { - continue; - } - target[len] = '\0'; - if (!strstr(target, "socket")) { - continue; - } - struct sockaddr_un addr; - socklen_t addrLen = sizeof(addr); - - // Obtains the peer address connected to the socket. - getpeername(atoi(entry->d_name), reinterpret_cast(&addr), &addrLen); - if (strstr(addr.sun_path, "hilogInput")) { - printf("FD: %s Connected to: %s\n", entry->d_name, addr.sun_path); - result++; - } - } - - closedir(dir); - return result; -} class HiLogBaseNDKTest : public testing::Test { public: @@ -353,10 +302,6 @@ HWTEST_F(HiLogBaseNDKTest, HilogBasePrintCheck, TestSize.Level1) bool result = CheckHiLogPrint(g_str[i].data()); EXPECT_EQ(result, true); } - - // Check the number of socket links to hilogInput. - int result = CheckHiLogdLinked(); - EXPECT_EQ(result, TWO); } } // namespace HiLogTest } // namespace HiviewDFX