From 6079487fde903a6ac510a36871b00b069b513726 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Tue, 3 Dec 2019 22:00:00 +0800 Subject: [PATCH] Enhancements Add validation of exclude/include values passed from URI argument. Update pref.ini. --- main.cpp | 4 ++-- misc.cpp | 13 +++++++++++++ misc.h | 1 + pref.ini | 5 ++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index dcacfd6..d5176fb 100644 --- a/main.cpp +++ b/main.cpp @@ -303,11 +303,11 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) std::vector nodes; int groupID = 0; - if(include.size()) + if(include.size() && regValid(include)) include_remarks.emplace_back(include); else include_remarks = def_include_remarks; - if(exclude.size()) + if(exclude.size() && regValid(exclude)) exclude_remarks.emplace_back(exclude); else exclude_remarks = def_exclude_remarks; diff --git a/misc.cpp b/misc.cpp index 8169ab2..c06ecc3 100644 --- a/misc.cpp +++ b/misc.cpp @@ -438,6 +438,19 @@ std::string replace_all_distinct(std::string str, std::string old_value, std::st return str; } +bool regValid(std::string ®) +{ + try + { + std::regex r(reg); + return true; + } + catch (std::regex_error &e) + { + return false; + } +} + bool regFind(std::string src, std::string target) { try diff --git a/misc.h b/misc.h index 0c5d6f5..5c992ae 100644 --- a/misc.h +++ b/misc.h @@ -40,6 +40,7 @@ bool is_str_utf8(std::string data); std::string getFormData(const std::string &raw_data); void sleep(int interval); +bool regValid(std::string ®); bool regFind(std::string src, std::string target); std::string regReplace(std::string src, std::string match, std::string rep); bool regMatch(std::string src, std::string match); diff --git a/pref.ini b/pref.ini index 2cadd60..f42dd14 100644 --- a/pref.ini +++ b/pref.ini @@ -6,7 +6,7 @@ api_mode=false default_url= ;Exclude nodes which remarks match the following patterns. Supports regular expression. -exclude_remarks=(流量|时间|官网|产品) +exclude_remarks=(到期|流量|时间|官网|产品) ;exclude_remarks=(other rule) ;Only include nodes which remarks match the following patterns. Supports regular expression. @@ -93,6 +93,9 @@ write_managed_config=true ;Address prefix for MANAGED-CONFIG info, without the trailing "/". managed_config_prefix=http://127.0.0.1:25500 +[surge_external_proxy] +;surge_ssr_path=/usr/bin/ssr-local + [emojis] add_emoji=true remove_old_emoji=true