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-09-09 10:34:49 +08:00
parent 394ccdf031
commit d6059f79ee
2 changed files with 7 additions and 3 deletions
services/param/watcher/proxy
test/fuzztest/parseueventconfig_fuzzer

@ -91,6 +91,7 @@ int32_t WatcherManager::AddWatcher(const std::string &keyPrefix, uint32_t remote
{
std::lock_guard<std::mutex> lock(watcherMutex_);
// get remote watcher and group
WATCHER_CHECK(keyPrefix.size() < PARAM_NAME_LEN_MAX, return -1, "Failed to verify keyPrefix.");
auto remoteWatcher = GetRemoteWatcher(remoteWatcherId);
WATCHER_CHECK(remoteWatcher != nullptr, return -1, "Can not find remote watcher %d", remoteWatcherId);
WATCHER_CHECK(remoteWatcher->CheckAgent(GetCallingPid()), return 0,
@ -115,6 +116,7 @@ int32_t WatcherManager::AddWatcher(const std::string &keyPrefix, uint32_t remote
int32_t WatcherManager::DelWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId)
{
std::lock_guard<std::mutex> lock(watcherMutex_);
WATCHER_CHECK(keyPrefix.size() < PARAM_NAME_LEN_MAX, return -1, "Failed to verify keyPrefix.");
auto group = GetWatcherGroup(keyPrefix);
WATCHER_CHECK(group != nullptr, return 0, "Can not find group %s", keyPrefix.c_str());
auto remoteWatcher = GetRemoteWatcher(remoteWatcherId);
@ -136,6 +138,7 @@ int32_t WatcherManager::DelWatcher(const std::string &keyPrefix, uint32_t remote
int32_t WatcherManager::RefreshWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId)
{
std::lock_guard<std::mutex> lock(watcherMutex_);
WATCHER_CHECK(keyPrefix.size() < PARAM_NAME_LEN_MAX, return -1, "Failed to verify keyPrefix.");
WATCHER_LOGV("Refresh watcher %s remoteWatcherId: %u", keyPrefix.c_str(), remoteWatcherId);
auto remoteWatcher = GetRemoteWatcher(remoteWatcherId);
WATCHER_CHECK(remoteWatcher != nullptr, return 0, "Can not find watcher %s %d", keyPrefix.c_str(), remoteWatcherId);

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