Description:Code optimization

Feature or Bugfix:Bugfix
Binary Source:No

Signed-off-by: lwx1281857 <linnanmu@h-partners.com>
This commit is contained in:
lwx1281857 2024-11-09 15:47:29 +08:00
parent f1b1085a21
commit 0c2f809059
12 changed files with 30 additions and 27 deletions

View File

@ -62,10 +62,10 @@ declare_args() {
init_startup_feature_system_call_switch = false init_startup_feature_system_call_switch = false
#deps param_watcher xcollie #deps param_watcher xcollie
paramwatcher_hicollie_enable = true init_paramwatcher_hicollie_enable = true
if (defined(global_parts_info) && if (defined(global_parts_info) &&
!defined(global_parts_info.hiviewdfx_hicollie)) { !defined(global_parts_info.hiviewdfx_hicollie)) {
paramwatcher_hicollie_enable = false init_paramwatcher_hicollie_enable = false
} }
# seccomp privilege # seccomp privilege

View File

@ -27,8 +27,9 @@ shared_library("libinitsync_shared") {
] ]
public_deps = [ "//base/startup/init/services/log:init_log" ] public_deps = [ "//base/startup/init/services/log:init_log" ]
public_external_deps = [ "bounds_checking_function:libsec_shared" ] external_deps = [ "bounds_checking_function:libsec_shared" ]
} }
static_library("libinitsync_static") { static_library("libinitsync_static") {
sources = [ "src/init_sync.c" ] sources = [ "src/init_sync.c" ]
include_dirs = [ include_dirs = [

View File

@ -23,7 +23,7 @@ if (defined(ohos_lite)) {
static_library("libsocket") { static_library("libsocket") {
sources = service_socket_sources sources = service_socket_sources
include_dirs = service_socket_include include_dirs = service_socket_include
external_deps = [ "bounds_checking_function:libsec_shared" ] external_deps = [ "bounds_checking_function:libsec_static" ]
} }
} }
} else { } else {
@ -32,7 +32,7 @@ if (defined(ohos_lite)) {
ohos_static_library("libsocket") { ohos_static_library("libsocket") {
sources = service_socket_sources sources = service_socket_sources
include_dirs = service_socket_include include_dirs = service_socket_include
external_deps = [ "bounds_checking_function:libsec_shared" ] external_deps = [ "bounds_checking_function:libsec_static" ]
part_name = "init" part_name = "init"
subsystem_name = "startup" subsystem_name = "startup"
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -60,7 +60,7 @@ ohos_shared_library("param_watcher") {
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ] external_deps += [ "hicollie:libhicollie" ]
defines = [ "HICOLLIE_ENABLE" ] defines = [ "HICOLLIE_ENABLE" ]
} }

View File

@ -54,10 +54,8 @@ int32_t WatcherManagerStub::OnRemoteRequest(uint32_t code,
} }
case static_cast<uint32_t>(ParamWatcherInterfaceCode::ADD_REMOTE_AGENT): { case static_cast<uint32_t>(ParamWatcherInterfaceCode::ADD_REMOTE_AGENT): {
auto remote = data.ReadRemoteObject(); auto remote = data.ReadRemoteObject();
// 0 is invalid watcherId
uint32_t id = data.ReadUint32();
sptr<IWatcher> watcher = new WatcherProxy(remote); sptr<IWatcher> watcher = new WatcherProxy(remote);
uint32_t remoteWatcherId = AddRemoteWatcher(id, watcher); uint32_t remoteWatcherId = AddRemoteWatcher(data.ReadUint32(), watcher);
reply.WriteUint32(remoteWatcherId); reply.WriteUint32(remoteWatcherId);
break; break;
} }

View File

@ -2972,7 +2972,7 @@ ohos_fuzztest("AddRemoteWatcherFuzzTest") {
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ] external_deps += [ "hicollie:libhicollie" ]
} }
@ -2984,7 +2984,7 @@ ohos_fuzztest("AddRemoteWatcherFuzzTest") {
] ]
sources += [ "addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp" ] sources += [ "addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp" ]
defines = [ "STARTUP_INIT_TEST" ] defines = [ "STARTUP_INIT_TEST" ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
defines += [ "HICOLLIE_ENABLE" ] defines += [ "HICOLLIE_ENABLE" ]
} }
} }
@ -3024,7 +3024,7 @@ ohos_fuzztest("DelRemoteWatcherFuzzTest") {
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ] external_deps += [ "hicollie:libhicollie" ]
} }
@ -3036,7 +3036,7 @@ ohos_fuzztest("DelRemoteWatcherFuzzTest") {
] ]
sources += [ "delremotewatcher_fuzzer/delremotewatcher_fuzzer.cpp" ] sources += [ "delremotewatcher_fuzzer/delremotewatcher_fuzzer.cpp" ]
defines = [ "STARTUP_INIT_TEST" ] defines = [ "STARTUP_INIT_TEST" ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
defines += [ "HICOLLIE_ENABLE" ] defines += [ "HICOLLIE_ENABLE" ]
} }
} }
@ -3075,7 +3075,7 @@ ohos_fuzztest("AddWatcherFuzzTest") {
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ] external_deps += [ "hicollie:libhicollie" ]
} }
@ -3087,7 +3087,7 @@ ohos_fuzztest("AddWatcherFuzzTest") {
] ]
sources += [ "addwatcher_fuzzer/addwatcher_fuzzer.cpp" ] sources += [ "addwatcher_fuzzer/addwatcher_fuzzer.cpp" ]
defines = [ "STARTUP_INIT_TEST" ] defines = [ "STARTUP_INIT_TEST" ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
defines += [ "HICOLLIE_ENABLE" ] defines += [ "HICOLLIE_ENABLE" ]
} }
} }
@ -3125,7 +3125,7 @@ ohos_fuzztest("DelWatcherFuzzTest") {
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ] external_deps += [ "hicollie:libhicollie" ]
} }
@ -3137,7 +3137,7 @@ ohos_fuzztest("DelWatcherFuzzTest") {
] ]
sources += [ "delwatcher_fuzzer/delwatcher_fuzzer.cpp" ] sources += [ "delwatcher_fuzzer/delwatcher_fuzzer.cpp" ]
defines = [ "STARTUP_INIT_TEST" ] defines = [ "STARTUP_INIT_TEST" ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
defines += [ "HICOLLIE_ENABLE" ] defines += [ "HICOLLIE_ENABLE" ]
} }
} }
@ -3175,7 +3175,7 @@ ohos_fuzztest("RefreshWatcherFuzzTest") {
"safwk:system_ability_fwk", "safwk:system_ability_fwk",
"samgr:samgr_proxy", "samgr:samgr_proxy",
] ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ] external_deps += [ "hicollie:libhicollie" ]
} }
@ -3187,7 +3187,7 @@ ohos_fuzztest("RefreshWatcherFuzzTest") {
] ]
sources += [ "refreshwatcher_fuzzer/refreshwatcher_fuzzer.cpp" ] sources += [ "refreshwatcher_fuzzer/refreshwatcher_fuzzer.cpp" ]
defines = [ "STARTUP_INIT_TEST" ] defines = [ "STARTUP_INIT_TEST" ]
if (paramwatcher_hicollie_enable) { if (init_paramwatcher_hicollie_enable) {
defines += [ "HICOLLIE_ENABLE" ] defines += [ "HICOLLIE_ENABLE" ]
} }
} }

View File

@ -22,12 +22,12 @@ namespace OHOS {
bool FuzzParseUeventConfig(const uint8_t* data, size_t size) bool FuzzParseUeventConfig(const uint8_t* data, size_t size)
{ {
bool result = false; bool result = false;
if (size == 0 && size > MAX_ALLOW_SIZE) { if (size == 0 || size > MAX_ALLOW_SIZE) {
return false; return false;
} }
std::string str(reinterpret_cast<const char*>(data), size); std::string str(reinterpret_cast<const char*>(data), size);
char *buffer = new char[size+1]; char *buffer = new char[size + 1];
int ret = strcpy_s(buffer, size+1, str.c_str()); int ret = strcpy_s(buffer, size + 1, str.c_str());
if (ret != 0) { if (ret != 0) {
delete[] buffer; delete[] buffer;
return false; return false;

View File

@ -37,8 +37,8 @@ using namespace testing::ext;
using namespace std; using namespace std;
using namespace OHOS; using namespace OHOS;
static int g_tokenType = OHOS::Security::AccessToken::TOKEN_HAP; int g_tokenType = OHOS::Security::AccessToken::TOKEN_HAP;
static int g_tokenVerifyResult = 0; int g_tokenVerifyResult = 0;
namespace OHOS { namespace OHOS {
namespace Security { namespace Security {
namespace AccessToken { namespace AccessToken {

View File

@ -13,9 +13,12 @@
* limitations under the License. * limitations under the License.
*/ */
#include "init_unittest.h"
#include <cerrno> #include <cerrno>
#include <cstdio> #include <cstdio>
#include <ctime> #include <ctime>
#include <sys/types.h> #include <sys/types.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -25,7 +28,6 @@
#include "init_cmds.h" #include "init_cmds.h"
#include "init_log.h" #include "init_log.h"
#include "init_service.h" #include "init_service.h"
#include "init_unittest.h"
#include "init_adapter.h" #include "init_adapter.h"
#include "init_utils.h" #include "init_utils.h"
#include "loop_event.h" #include "loop_event.h"

View File

@ -370,6 +370,8 @@ HWTEST_F(WatcherProxyUnitTest, Init_TestStop_001, TestSize.Level0)
{ {
WatcherProxyUnitTest test; WatcherProxyUnitTest test;
uint32_t watcherId = 0; uint32_t watcherId = 0;
fdsan_set_error_level(FDSAN_ERROR_LEVEL_DISABLED);
test.TestAddRemoteWatcher(getpid(), watcherId); test.TestAddRemoteWatcher(getpid(), watcherId);
test.TestAddWatcher("test.permission.watcher.stop", watcherId); test.TestAddWatcher("test.permission.watcher.stop", watcherId);
test.TestStop(); test.TestStop();

View File

@ -50,7 +50,7 @@ HWTEST_F(SysparaUnitTest, parameterTest001, TestSize.Level0)
printf("MarketName =%s\n", GetMarketName()); printf("MarketName =%s\n", GetMarketName());
printf("ProductSeries =%s\n", GetProductSeries()); printf("ProductSeries =%s\n", GetProductSeries());
printf("ProductModel =%s\n", GetProductModel()); printf("ProductModel =%s\n", GetProductModel());
printf("ProductModel =%s\n", GetProductModelAlias()); printf("ProductModelAlias =%s\n", GetProductModelAlias());
printf("SoftwareModel =%s\n", GetSoftwareModel()); printf("SoftwareModel =%s\n", GetSoftwareModel());
printf("HardwareModel =%s\n", GetHardwareModel()); printf("HardwareModel =%s\n", GetHardwareModel());
printf("Software profile =%s\n", GetHardwareProfile()); printf("Software profile =%s\n", GetHardwareProfile());