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