Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add validity verification of cli export level parameters #213

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions application/logbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ bool LogBackend::exportAppLogsByCondition(const QString &outDir, const QString &
}
}

// 级别有效性判断
if (!level.isEmpty() && level2Id(level) == -2) {
qCWarning(logBackend) << "invalid level parameter: " << level;
return false;
}

qCInfo(logBackend) << "appName:" << appName << "period:" << period << "level:" << level << "keyword:" << keyword;

TIME_RANGE timeRange = getTimeRange(periodId);
Expand Down Expand Up @@ -809,16 +815,15 @@ void LogBackend::onExportProgress(int nCur, int nTotal)

void LogBackend::onExportResult(bool isSuccess)
{
Utils::resetToNormalAuth(m_outPath);

if (isSuccess) {
qCInfo(logBackend) << "export success.";

qApp->quit();
} else {
qCWarning(logBackend) << "export failed.";
qApp->exit(-1);
}

Utils::resetToNormalAuth(m_outPath);

qApp->exit(-1);
}

QList<LOG_MSG_BOOT> LogBackend::filterBoot(BOOT_FILTERS ibootFilter, const QList<LOG_MSG_BOOT> &iList)
Expand Down Expand Up @@ -1064,6 +1069,23 @@ bool LogBackend::parseData(const LOG_FLAG &flag, const QString &period, const QS
}
}

// 常规级别有效性判断
if (flag == JOURNAL || flag == Dmesg || flag == BOOT_KLU || flag == APP) {
if (!condition.isEmpty() && level2Id(condition) == -2) {
qCWarning(logBackend) << "invalid level parameter: " << condition;
return false;
}

}

// dnf级别有效性判断
if (flag == Dnf) {
if (!condition.isEmpty() && dnfLevel2Id(condition) == DNFINVALID) {
qCWarning(logBackend) << "invalid level parameter: " << condition;
return false;
}
}

qCInfo(logBackend) << "parsing ..." << "period:" << period << "condition:" << condition << "keyword:" << m_currentSearchStr;

TIME_RANGE timeRange = getTimeRange(periodId);
Expand Down Expand Up @@ -1530,7 +1552,7 @@ BUTTONID LogBackend::period2Enum(const QString &period)

int LogBackend::level2Id(const QString &level)
{
int lId = -1;
int lId = -2;
if (level == "debug" || level == "7")
lId = 7;
if (level == "info" || level == "6")
Expand All @@ -1547,13 +1569,15 @@ int LogBackend::level2Id(const QString &level)
lId = 1;
else if (level == "emerg" || level == "0")
lId = 0;
else if (level == "all")
lId = -1;

return lId;
}

DNFPRIORITY LogBackend::dnfLevel2Id(const QString &level)
{
DNFPRIORITY eId = DNFLVALL;
DNFPRIORITY eId = DNFINVALID;
if (level == "trace" || level == "6")
eId = TRACE;
else if (level == "debug" || level == "5")
Expand All @@ -1568,6 +1592,8 @@ DNFPRIORITY LogBackend::dnfLevel2Id(const QString &level)
eId = CRITICAL;
else if (level == "supercritical" || level == "supercrit" || level == "0")
eId = SUPERCRITICAL;
else if (level == "all")
eId = DNFLVALL;

return eId;
}
Expand Down
3 changes: 2 additions & 1 deletion application/structdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ enum PRIORITY { LVALL = -1,
NOTICE,
INF,
DEB };
enum DNFPRIORITY { DNFLVALL = -1,
enum DNFPRIORITY { DNFINVALID = -2,
DNFLVALL,
TRACE,
SUBDEBUG,
DDEBUG,
Expand Down