From 3994e845ad38d00db2696cca7c2a0e65ae10decc Mon Sep 17 00:00:00 2001 From: Loong Date: Fri, 9 Aug 2024 16:50:17 +0100 Subject: [PATCH] fix: validate filename before using it to avoid crash (#10138) When custom mode is enabled and filename is not set, the program will crash. This patch adds a check to validate the filename before using it to avoid the crash. --- src/MaaCore/Task/Interface/InfrastTask.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/MaaCore/Task/Interface/InfrastTask.cpp b/src/MaaCore/Task/Interface/InfrastTask.cpp index 435a7bc6cf..aa912c5dbe 100644 --- a/src/MaaCore/Task/Interface/InfrastTask.cpp +++ b/src/MaaCore/Task/Interface/InfrastTask.cpp @@ -143,7 +143,12 @@ bool asst::InfrastTask::set_params(const json::value& params) m_replenish_task_ptr->set_enable(replenish); if (is_custom && !m_running) { - std::string filename = params.at("filename").as_string(); + auto filename_opt = params.find("filename"); + if (!filename_opt) { + Log.error("filename is not set while custom mode is enabled"); + return false; + } + std::string filename = filename_opt.value(); int index = params.get("plan_index", 0); try {