1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hiappevent_verify.h"
17
18 #include <cctype>
19 #include <iterator>
20 #include <unordered_set>
21
22 #include "hiappevent_base.h"
23 #include "hiappevent_config.h"
24 #include "hilog/log.h"
25
26 #undef LOG_DOMAIN
27 #define LOG_DOMAIN 0xD002D07
28
29 #undef LOG_TAG
30 #define LOG_TAG "HiAppEventVerify"
31
32 using namespace OHOS::HiviewDFX::ErrorCode;
33
34 namespace OHOS {
35 namespace HiviewDFX {
36 namespace {
37 constexpr size_t MAX_LEN_OF_WATCHER = 32;
38 constexpr size_t MAX_LEN_OF_DOMAIN = 32;
39 static constexpr int MAX_LENGTH_OF_EVENT_NAME = 48;
40 static constexpr int MAX_LENGTH_OF_PARAM_NAME = 32;
41 static constexpr unsigned int MAX_NUM_OF_PARAMS = 32;
42 static constexpr size_t MAX_LENGTH_OF_STR_PARAM = 8 * 1024;
43 static constexpr size_t MAX_LENGTH_OF_SPECIAL_STR_PARAM = 1024 * 1024;
44 static constexpr int MAX_SIZE_OF_LIST_PARAM = 100;
45 static constexpr int MAX_LENGTH_OF_USER_INFO_NAME = 256;
46 static constexpr int MAX_LENGTH_OF_USER_ID_VALUE = 256;
47 static constexpr int MAX_LENGTH_OF_USER_PROPERTY_VALUE = 1024;
48 static constexpr int MAX_LENGTH_OF_PROCESSOR_NAME = 256;
49 static constexpr int MAX_LEN_OF_BATCH_REPORT = 1000;
50 static constexpr size_t MAX_NUM_OF_CUSTOM_CONFIGS = 32;
51 static constexpr size_t MAX_LENGTH_OF_CUSTOM_CONFIG_NAME = 32;
52 static constexpr size_t MAX_LENGTH_OF_CUSTOM_CONFIG_VALUE = 1024;
53 static constexpr size_t MAX_NUM_OF_CUSTOM_PARAMS = 64;
54 static constexpr size_t MAX_LENGTH_OF_CUSTOM_PARAM = 1024;
55
IsValidName(const std::string & name,size_t maxSize,bool allowDollarSign=true)56 bool IsValidName(const std::string& name, size_t maxSize, bool allowDollarSign = true)
57 {
58 if (name.empty() || name.length() > maxSize) {
59 return false;
60 }
61 // start char is [$a-zA-Z] or [a-zA-Z]
62 if (!isalpha(name[0]) && (!allowDollarSign || name[0] != '$')) {
63 return false;
64 }
65 // end char is [a-zA-Z0-9]
66 if (name.length() > 1 && (!isalnum(name.back()))) {
67 return false;
68 }
69 // middle char is [a-zA-Z0-9_]
70 for (size_t i = 1; i < name.length() - 1; ++i) {
71 if (!isalnum(name[i]) && name[i] != '_') {
72 return false;
73 }
74 }
75 return true;
76 }
77
CheckParamName(const std::string & paramName)78 bool CheckParamName(const std::string& paramName)
79 {
80 return IsValidName(paramName, MAX_LENGTH_OF_PARAM_NAME);
81 }
82
EscapeStringValue(std::string & value)83 void EscapeStringValue(std::string &value)
84 {
85 std::string escapeValue;
86 for (auto it = value.begin(); it != value.end(); it++) {
87 switch (*it) {
88 case '\\':
89 escapeValue.append("\\\\");
90 break;
91 case '\"':
92 escapeValue.append("\\\"");
93 break;
94 case '\b':
95 escapeValue.append("\\b");
96 break;
97 case '\f':
98 escapeValue.append("\\f");
99 break;
100 case '\n':
101 escapeValue.append("\\n");
102 break;
103 case '\r':
104 escapeValue.append("\\r");
105 break;
106 case '\t':
107 escapeValue.append("\\t");
108 break;
109 default:
110 escapeValue.push_back(*it);
111 break;
112 }
113 }
114 value = escapeValue;
115 }
116
CheckStrParamLength(std::string & strParamValue,size_t maxLen=MAX_LENGTH_OF_STR_PARAM)117 bool CheckStrParamLength(std::string& strParamValue, size_t maxLen = MAX_LENGTH_OF_STR_PARAM)
118 {
119 if (strParamValue.empty()) {
120 HILOG_WARN(LOG_CORE, "str param value is empty.");
121 return true;
122 }
123
124 if (strParamValue.length() > maxLen) {
125 return false;
126 }
127
128 EscapeStringValue(strParamValue);
129 return true;
130 }
131
CheckListValueSize(AppEventParamType type,AppEventParamValue::ValueUnion & vu)132 bool CheckListValueSize(AppEventParamType type, AppEventParamValue::ValueUnion& vu)
133 {
134 if (type == AppEventParamType::BVECTOR && vu.bs_.size() > MAX_SIZE_OF_LIST_PARAM) {
135 vu.bs_.resize(MAX_SIZE_OF_LIST_PARAM);
136 } else if (type == AppEventParamType::CVECTOR && vu.cs_.size() > MAX_SIZE_OF_LIST_PARAM) {
137 vu.cs_.resize(MAX_SIZE_OF_LIST_PARAM);
138 } else if (type == AppEventParamType::SHVECTOR && vu.shs_.size() > MAX_SIZE_OF_LIST_PARAM) {
139 vu.shs_.resize(MAX_SIZE_OF_LIST_PARAM);
140 } else if (type == AppEventParamType::IVECTOR && vu.is_.size() > MAX_SIZE_OF_LIST_PARAM) {
141 vu.is_.resize(MAX_SIZE_OF_LIST_PARAM);
142 } else if (type == AppEventParamType::LLVECTOR && vu.lls_.size() > MAX_SIZE_OF_LIST_PARAM) {
143 vu.lls_.resize(MAX_SIZE_OF_LIST_PARAM);
144 } else if (type == AppEventParamType::FVECTOR && vu.fs_.size() > MAX_SIZE_OF_LIST_PARAM) {
145 vu.fs_.resize(MAX_SIZE_OF_LIST_PARAM);
146 } else if (type == AppEventParamType::DVECTOR && vu.ds_.size() > MAX_SIZE_OF_LIST_PARAM) {
147 vu.ds_.resize(MAX_SIZE_OF_LIST_PARAM);
148 } else if (type == AppEventParamType::STRVECTOR && vu.strs_.size() > MAX_SIZE_OF_LIST_PARAM) {
149 vu.strs_.resize(MAX_SIZE_OF_LIST_PARAM);
150 } else {
151 return true;
152 }
153
154 return false;
155 }
156
CheckStringLengthOfList(std::vector<std::string> & strs,size_t maxTotalLen=0)157 bool CheckStringLengthOfList(std::vector<std::string>& strs, size_t maxTotalLen = 0)
158 {
159 if (strs.empty()) {
160 return true;
161 }
162 size_t totalLen = 0;
163 for (auto it = strs.begin(); it != strs.end(); it++) {
164 if (!CheckStrParamLength(*it)) {
165 return false;
166 }
167 totalLen += (*it).length();
168 }
169 if (maxTotalLen > 0 && totalLen > maxTotalLen) {
170 return false;
171 }
172 return true;
173 }
174
CheckParamsNum(std::list<AppEventParam> & baseParams)175 bool CheckParamsNum(std::list<AppEventParam>& baseParams)
176 {
177 if (baseParams.size() == 0) {
178 return true;
179 }
180
181 auto listSize = baseParams.size();
182 if (listSize > MAX_NUM_OF_PARAMS) {
183 auto delStartPtr = baseParams.begin();
184 std::advance(delStartPtr, MAX_NUM_OF_PARAMS);
185 baseParams.erase(delStartPtr, baseParams.end());
186 return false;
187 }
188
189 return true;
190 }
191
VerifyAppEventParam(AppEventParam & param,std::unordered_set<std::string> & paramNames,int & verifyRes)192 bool VerifyAppEventParam(AppEventParam& param, std::unordered_set<std::string>& paramNames, int& verifyRes)
193 {
194 std::string name = param.name;
195 if (paramNames.find(name) != paramNames.end()) {
196 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because param is duplicate.", name.c_str());
197 verifyRes = ERROR_DUPLICATE_PARAM;
198 return false;
199 }
200
201 if (!CheckParamName(name)) {
202 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because the paramName is invalid.", name.c_str());
203 verifyRes = ERROR_INVALID_PARAM_NAME;
204 return false;
205 }
206
207 const std::unordered_set<std::string> tempTrueNames = {"crash", "anr"};
208 size_t maxLen = tempTrueNames.find(name) == tempTrueNames.end() ? MAX_LENGTH_OF_STR_PARAM :
209 MAX_LENGTH_OF_SPECIAL_STR_PARAM;
210 if (param.type == AppEventParamType::STRING && !CheckStrParamLength(param.value.valueUnion.str_, maxLen)) {
211 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because the string length exceeds %{public}zu.",
212 name.c_str(), maxLen);
213 verifyRes = ERROR_INVALID_PARAM_VALUE_LENGTH;
214 return false;
215 }
216
217 if (param.type == AppEventParamType::STRVECTOR && !CheckStringLengthOfList(param.value.valueUnion.strs_)) {
218 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because the string length of list exceeds 8192.",
219 name.c_str());
220 verifyRes = ERROR_INVALID_PARAM_VALUE_LENGTH;
221 return false;
222 }
223
224 if (param.type > AppEventParamType::STRING && !CheckListValueSize(param.type, param.value.valueUnion)) {
225 HILOG_WARN(LOG_CORE, "list param=%{public}s is truncated because the list size exceeds 100.", name.c_str());
226 verifyRes = ERROR_INVALID_LIST_PARAM_SIZE;
227 return true;
228 }
229 return true;
230 }
231
VerifyCustomAppEventParam(AppEventParam & param,std::unordered_set<std::string> & paramNames)232 int VerifyCustomAppEventParam(AppEventParam& param, std::unordered_set<std::string>& paramNames)
233 {
234 std::string name = param.name;
235 if (paramNames.find(name) != paramNames.end()) {
236 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because param is duplicate.", name.c_str());
237 return ERROR_DUPLICATE_PARAM;
238 }
239
240 if (!CheckParamName(name)) {
241 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because the paramName is invalid.", name.c_str());
242 return ERROR_INVALID_PARAM_NAME;
243 }
244
245 if (param.type == AppEventParamType::STRING
246 && !CheckStrParamLength(param.value.valueUnion.str_, MAX_LENGTH_OF_CUSTOM_PARAM)) {
247 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because the string length exceeds %{public}zu.",
248 name.c_str(), MAX_LENGTH_OF_CUSTOM_PARAM);
249 return ERROR_INVALID_PARAM_VALUE_LENGTH;
250 }
251
252 if (param.type == AppEventParamType::STRVECTOR
253 && !CheckStringLengthOfList(param.value.valueUnion.strs_, MAX_LENGTH_OF_CUSTOM_PARAM)) {
254 HILOG_WARN(LOG_CORE, "param=%{public}s is discarded because the string length of list exceeds %{public}zu.",
255 name.c_str(), MAX_LENGTH_OF_CUSTOM_PARAM);
256 return ERROR_INVALID_PARAM_VALUE_LENGTH;
257 }
258
259 return HIAPPEVENT_VERIFY_SUCCESSFUL;
260 }
261
262 using VerifyReportConfigFunc = int (*)(ReportConfig& config);
VerifyNameOfReportConfig(ReportConfig & config)263 int VerifyNameOfReportConfig(ReportConfig& config)
264 {
265 if (!IsValidProcessorName(config.name)) {
266 HILOG_ERROR(LOG_CORE, "invalid name=%{public}s", config.name.c_str());
267 return -1;
268 }
269 return 0;
270 }
271
VerifyRouteInfoOfReportConfig(ReportConfig & config)272 int VerifyRouteInfoOfReportConfig(ReportConfig& config)
273 {
274 if (!IsValidRouteInfo(config.routeInfo)) {
275 HILOG_WARN(LOG_CORE, "invalid routeInfo=%{public}s", config.routeInfo.c_str());
276 config.routeInfo = "";
277 }
278 return 0;
279 }
280
VerifyAppIdOfReportConfig(ReportConfig & config)281 int VerifyAppIdOfReportConfig(ReportConfig& config)
282 {
283 if (!IsValidAppId(config.appId)) {
284 HILOG_WARN(LOG_CORE, "invalid appId=%{public}s", config.appId.c_str());
285 config.appId = "";
286 }
287 return 0;
288 }
289
VerifyTriggerCondOfReportConfig(ReportConfig & config)290 int VerifyTriggerCondOfReportConfig(ReportConfig& config)
291 {
292 if (!IsValidBatchReport(config.triggerCond.row)) {
293 HILOG_WARN(LOG_CORE, "invalid triggerCond.row=%{public}d", config.triggerCond.row);
294 config.triggerCond.row = 0;
295 }
296 if (!IsValidPeriodReport(config.triggerCond.timeout)) {
297 HILOG_WARN(LOG_CORE, "invalid triggerCond.timeout=%{public}d", config.triggerCond.row);
298 config.triggerCond.timeout = 0;
299 }
300 // processor does not support the size
301 config.triggerCond.size = 0;
302 return 0;
303 }
304
VerifyUserIdNamesOfReportConfig(ReportConfig & config)305 int VerifyUserIdNamesOfReportConfig(ReportConfig& config)
306 {
307 for (const auto& name : config.userIdNames) {
308 if (!IsValidUserIdName(name)) {
309 HILOG_WARN(LOG_CORE, "invalid user id name=%{public}s", name.c_str());
310 config.userIdNames.clear();
311 break;
312 }
313 }
314 return 0;
315 }
316
VerifyUserPropertyNamesOfReportConfig(ReportConfig & config)317 int VerifyUserPropertyNamesOfReportConfig(ReportConfig& config)
318 {
319 for (const auto& name : config.userPropertyNames) {
320 if (!IsValidUserIdName(name)) {
321 HILOG_WARN(LOG_CORE, "invalid user property name=%{public}s", name.c_str());
322 config.userPropertyNames.clear();
323 break;
324 }
325 }
326 return 0;
327 }
328
VerifyEventConfigsOfReportConfig(ReportConfig & reportConfig)329 int VerifyEventConfigsOfReportConfig(ReportConfig& reportConfig)
330 {
331 for (const auto& eventConfig : reportConfig.eventConfigs) {
332 if (!IsValidEventConfig(eventConfig)) {
333 HILOG_WARN(LOG_CORE, "invalid event configs, domain=%{public}s, name=%{public}s",
334 eventConfig.domain.c_str(), eventConfig.name.c_str());
335 reportConfig.eventConfigs.clear();
336 break;
337 }
338 }
339 return 0;
340 }
341
VerifyConfigIdOfReportConfig(ReportConfig & config)342 int VerifyConfigIdOfReportConfig(ReportConfig& config)
343 {
344 if (!IsValidConfigId(config.configId)) {
345 HILOG_WARN(LOG_CORE, "invalid configId=%{public}d", config.configId);
346 config.configId = 0;
347 }
348 return 0;
349 }
350
VerifyCustomConfigsOfReportConfig(ReportConfig & config)351 int VerifyCustomConfigsOfReportConfig(ReportConfig& config)
352 {
353 if (!IsValidCustomConfigsNum(config.customConfigs.size())) {
354 HILOG_WARN(LOG_CORE, "invalid keys size=%{public}zu", config.customConfigs.size());
355 config.customConfigs.clear();
356 return 0;
357 }
358 for (const auto& item : config.customConfigs) {
359 if (!IsValidCustomConfig(item.first, item.second)) {
360 HILOG_WARN(LOG_CORE, "invalid key name=%{public}s", item.first.c_str());
361 config.customConfigs.clear();
362 break;
363 }
364 }
365 return 0;
366 }
367 }
368
IsValidDomain(const std::string & eventDomain)369 bool IsValidDomain(const std::string& eventDomain)
370 {
371 return IsValidName(eventDomain, MAX_LEN_OF_DOMAIN, false);
372 }
373
IsValidEventName(const std::string & eventName)374 bool IsValidEventName(const std::string& eventName)
375 {
376 const std::string eventPrefix = "hiappevent.";
377 return eventName.find(eventPrefix) == 0 ?
378 IsValidName(eventName.substr(eventPrefix.length()), MAX_LENGTH_OF_EVENT_NAME - eventPrefix.length()) :
379 IsValidName(eventName, MAX_LENGTH_OF_EVENT_NAME);
380 }
381
IsValidWatcherName(const std::string & watcherName)382 bool IsValidWatcherName(const std::string& watcherName)
383 {
384 return IsValidName(watcherName, MAX_LEN_OF_WATCHER, false);
385 }
386
IsValidEventType(int eventType)387 bool IsValidEventType(int eventType)
388 {
389 return eventType >= 1 && eventType <= 4; // 1-4: value range of event type
390 }
391
VerifyAppEvent(std::shared_ptr<AppEventPack> event)392 int VerifyAppEvent(std::shared_ptr<AppEventPack> event)
393 {
394 if (HiAppEventConfig::GetInstance().GetDisable()) {
395 HILOG_ERROR(LOG_CORE, "the HiAppEvent function is disabled.");
396 return ERROR_HIAPPEVENT_DISABLE;
397 }
398 if (!IsValidDomain(event->GetDomain())) {
399 HILOG_ERROR(LOG_CORE, "eventDomain=%{public}s is invalid.", event->GetDomain().c_str());
400 return ERROR_INVALID_EVENT_DOMAIN;
401 }
402 if (!IsValidEventName(event->GetName())) {
403 HILOG_ERROR(LOG_CORE, "eventName=%{public}s is invalid.", event->GetName().c_str());
404 return ERROR_INVALID_EVENT_NAME;
405 }
406
407 int verifyRes = HIAPPEVENT_VERIFY_SUCCESSFUL;
408 std::list<AppEventParam>& baseParams = event->baseParams_;
409 std::unordered_set<std::string> paramNames;
410 for (auto it = baseParams.begin(); it != baseParams.end();) {
411 if (!VerifyAppEventParam(*it, paramNames, verifyRes)) {
412 baseParams.erase(it++);
413 continue;
414 }
415 paramNames.emplace(it->name);
416 it++;
417 }
418
419 if (!CheckParamsNum(baseParams)) {
420 HILOG_WARN(LOG_CORE, "params that exceed 32 are discarded because the number of params cannot exceed 32.");
421 verifyRes = ERROR_INVALID_PARAM_NUM;
422 }
423
424 return verifyRes;
425 }
426
VerifyCustomEventParams(std::shared_ptr<AppEventPack> event)427 int VerifyCustomEventParams(std::shared_ptr<AppEventPack> event)
428 {
429 if (HiAppEventConfig::GetInstance().GetDisable()) {
430 HILOG_ERROR(LOG_CORE, "the HiAppEvent function is disabled.");
431 return ERROR_HIAPPEVENT_DISABLE;
432 }
433 if (!IsValidDomain(event->GetDomain())) {
434 HILOG_ERROR(LOG_CORE, "eventDomain=%{public}s is invalid.", event->GetDomain().c_str());
435 return ERROR_INVALID_EVENT_DOMAIN;
436 }
437 if (!event->GetName().empty() && !IsValidEventName(event->GetName())) {
438 HILOG_ERROR(LOG_CORE, "eventName=%{public}s is invalid.", event->GetName().c_str());
439 return ERROR_INVALID_EVENT_NAME;
440 }
441
442 std::list<AppEventParam>& baseParams = event->baseParams_;
443 if (baseParams.size() > MAX_NUM_OF_CUSTOM_PARAMS) {
444 HILOG_WARN(LOG_CORE, "params that exceed 64 are discarded because the number of params cannot exceed 64.");
445 return ERROR_INVALID_CUSTOM_PARAM_NUM;
446 }
447 std::unordered_set<std::string> paramNames;
448 for (auto it = baseParams.begin(); it != baseParams.end(); ++it) {
449 if (int ret = VerifyCustomAppEventParam(*it, paramNames); ret != HIAPPEVENT_VERIFY_SUCCESSFUL) {
450 return ret;
451 }
452 }
453 return HIAPPEVENT_VERIFY_SUCCESSFUL;
454 }
455
IsValidPropName(const std::string & name,size_t maxSize)456 bool IsValidPropName(const std::string& name, size_t maxSize)
457 {
458 if (name.empty() || name.length() > maxSize) {
459 return false;
460 }
461 // start char is [a-zA-Z_$]
462 if (!isalpha(name[0]) && name[0] != '_' && name[0] != '$') {
463 return false;
464 }
465 // other char is [a-zA-Z0-9_$]
466 for (size_t i = 1; i < name.length(); ++i) {
467 if (!isalnum(name[i]) && name[i] != '_' && name[i] != '$') {
468 return false;
469 }
470 }
471 return true;
472 }
473
IsValidPropValue(const std::string & val,size_t maxSize)474 bool IsValidPropValue(const std::string& val, size_t maxSize)
475 {
476 return !val.empty() && val.length() <= maxSize;
477 }
478
IsValidProcessorName(const std::string & name)479 bool IsValidProcessorName(const std::string& name)
480 {
481 return IsValidPropName(name, MAX_LENGTH_OF_PROCESSOR_NAME);
482 }
483
IsValidRouteInfo(const std::string & name)484 bool IsValidRouteInfo(const std::string& name)
485 {
486 return name.length() <= MAX_LENGTH_OF_STR_PARAM;
487 }
488
IsValidAppId(const std::string & name)489 bool IsValidAppId(const std::string& name)
490 {
491 return name.length() <= MAX_LENGTH_OF_STR_PARAM;
492 }
493
IsValidPeriodReport(int timeout)494 bool IsValidPeriodReport(int timeout)
495 {
496 return timeout >= 0;
497 }
498
IsValidBatchReport(int count)499 bool IsValidBatchReport(int count)
500 {
501 return count >= 0 && count <= MAX_LEN_OF_BATCH_REPORT;
502 }
503
IsValidUserIdName(const std::string & name)504 bool IsValidUserIdName(const std::string& name)
505 {
506 return IsValidPropName(name, MAX_LENGTH_OF_USER_INFO_NAME);
507 }
508
IsValidUserIdValue(const std::string & value)509 bool IsValidUserIdValue(const std::string& value)
510 {
511 return IsValidPropValue(value, MAX_LENGTH_OF_USER_ID_VALUE);
512 }
513
IsValidUserPropName(const std::string & name)514 bool IsValidUserPropName(const std::string& name)
515 {
516 return IsValidPropName(name, MAX_LENGTH_OF_USER_INFO_NAME);
517 }
518
IsValidUserPropValue(const std::string & value)519 bool IsValidUserPropValue(const std::string& value)
520 {
521 return IsValidPropValue(value, MAX_LENGTH_OF_USER_PROPERTY_VALUE);
522 }
523
IsValidEventConfig(const EventConfig & eventCfg)524 bool IsValidEventConfig(const EventConfig& eventCfg)
525 {
526 if (eventCfg.domain.empty() && eventCfg.name.empty()) {
527 return false;
528 }
529 if (!eventCfg.domain.empty() && !IsValidDomain(eventCfg.domain)) {
530 return false;
531 }
532 if (!eventCfg.name.empty() && !IsValidEventName(eventCfg.name)) {
533 return false;
534 }
535 return true;
536 }
537
IsValidConfigId(int configId)538 bool IsValidConfigId(int configId)
539 {
540 return configId >= 0;
541 }
542
IsValidCustomConfigsNum(size_t num)543 bool IsValidCustomConfigsNum(size_t num)
544 {
545 return num <= MAX_NUM_OF_CUSTOM_CONFIGS;
546 }
547
IsValidCustomConfig(const std::string & name,const std::string & value)548 bool IsValidCustomConfig(const std::string& name, const std::string& value)
549 {
550 if (!IsValidName(name, MAX_LENGTH_OF_CUSTOM_CONFIG_NAME) || value.length() > MAX_LENGTH_OF_CUSTOM_CONFIG_VALUE) {
551 return false;
552 }
553 return true;
554 }
555
VerifyReportConfig(ReportConfig & config)556 int VerifyReportConfig(ReportConfig& config)
557 {
558 const VerifyReportConfigFunc verifyFuncs[] = {
559 VerifyNameOfReportConfig,
560 VerifyRouteInfoOfReportConfig,
561 VerifyAppIdOfReportConfig,
562 VerifyTriggerCondOfReportConfig,
563 VerifyUserIdNamesOfReportConfig,
564 VerifyUserPropertyNamesOfReportConfig,
565 VerifyEventConfigsOfReportConfig,
566 VerifyConfigIdOfReportConfig,
567 VerifyCustomConfigsOfReportConfig,
568 };
569 for (const auto verifyFunc : verifyFuncs) {
570 if (verifyFunc(config) != 0) {
571 return -1;
572 }
573 }
574 return 0;
575 }
576 } // namespace HiviewDFX
577 } // namespace OHOS
578