From c889b71c3ce9393f03a2e375a44b25fbf2d72e79 Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Sat, 30 Mar 2024 14:01:06 -0400 Subject: [PATCH] Add regex check to gates and e2 find (#3023) --- .../gmod_wire_expression2/core/find.lua | 17 +++++++++++++++++ lua/wire/gates/string.lua | 1 + 2 files changed, 18 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/find.lua b/lua/entities/gmod_wire_expression2/core/find.lua index 67fd4a476d..8a2eddcd45 100644 --- a/lua/entities/gmod_wire_expression2/core/find.lua +++ b/lua/entities/gmod_wire_expression2/core/find.lua @@ -8,6 +8,9 @@ local function replace_match(a,b) return string.match( string.Replace(a,"-","__"), string.Replace(b,"-","__") ) end +-- String used to check regex complexities +local sample_string = string.rep(" ", 40) + -- -- some generic filter criteria -- -- local function filter_all() return true end @@ -516,12 +519,14 @@ end --- Exclude entities with this model (or partial model name) from future finds e2function void findExcludeModel(string model) + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end self.data.find.bl_model[string.lower(model)] = true invalidate_filters(self) end --- Exclude entities with this class (or partial class name) from future finds e2function void findExcludeClass(string class) + if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end self.data.find.bl_class[string.lower(class)] = true invalidate_filters(self) end @@ -574,12 +579,14 @@ end --- Remove entities with this model (or partial model name) from the blacklist e2function void findAllowModel(string model) + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end self.data.find.bl_model[string.lower(model)] = nil invalidate_filters(self) end --- Remove entities with this class (or partial class name) from the blacklist e2function void findAllowClass(string class) + if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end self.data.find.bl_class[string.lower(class)] = nil invalidate_filters(self) end @@ -632,12 +639,14 @@ end --- Include entities with this model (or partial model name) in future finds, and remove others not in the whitelist e2function void findIncludeModel(string model) + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end self.data.find.wl_model[string.lower(model)] = true invalidate_filters(self) end --- Include entities with this class (or partial class name) in future finds, and remove others not in the whitelist e2function void findIncludeClass(string class) + if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end self.data.find.wl_class[string.lower(class)] = true invalidate_filters(self) end @@ -690,12 +699,14 @@ end --- Remove entities with this model (or partial model name) from the whitelist e2function void findDisallowModel(string model) + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end self.data.find.wl_model[string.lower(model)] = nil invalidate_filters(self) end --- Remove entities with this class (or partial class name) from the whitelist e2function void findDisallowClass(string class) + if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", nil) end self.data.find.wl_class[string.lower(class)] = nil invalidate_filters(self) end @@ -865,6 +876,7 @@ end --- Filters the list of entities by removing all entities that are NOT of this class e2function number findClipToClass(string class) + if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", 0) end class = string.lower(class) return applyClip(self, function(ent) if !IsValid(ent) then return false end @@ -874,6 +886,7 @@ end --- Filters the list of entities by removing all entities that are of this class e2function number findClipFromClass(string class) + if not pcall(WireLib.CheckRegex, sample_string, class) then return self:throw("Search string too complex!", 0) end return applyClip(self, function(ent) if !IsValid(ent) then return false end return not replace_match(string.lower(ent:GetClass()), class) @@ -882,6 +895,7 @@ end --- Filters the list of entities by removing all entities that do NOT have this model e2function number findClipToModel(string model) + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", 0) end return applyClip(self, function(ent) if !IsValid(ent) then return false end return replace_match(string.lower(ent:GetModel() or ""), model) @@ -890,6 +904,7 @@ end --- Filters the list of entities by removing all entities that do have this model e2function number findClipFromModel(string model) + if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", 0) end return applyClip(self, function(ent) if !IsValid(ent) then return false end return not replace_match(string.lower(ent:GetModel() or ""), model) @@ -898,6 +913,7 @@ end --- Filters the list of entities by removing all entities that do NOT have this name e2function number findClipToName(string name) + if not pcall(WireLib.CheckRegex, sample_string, name) then return self:throw("Search string too complex!", 0) end return applyClip(self, function(ent) if !IsValid(ent) then return false end return replace_match(string.lower(ent:GetName()), name) @@ -906,6 +922,7 @@ end --- Filters the list of entities by removing all entities that do have this name e2function number findClipFromName(string name) + if not pcall(WireLib.CheckRegex, sample_string, name) then return self:throw("Search string too complex!", 0) end return applyClip(self, function(ent) if !IsValid(ent) then return false end return not replace_match(string.lower(ent:GetName()), name) diff --git a/lua/wire/gates/string.lua b/lua/wire/gates/string.lua index ca3408acb6..374db103d4 100644 --- a/lua/wire/gates/string.lua +++ b/lua/wire/gates/string.lua @@ -189,6 +189,7 @@ GateActions["string_replace"] = { if not B then B = "" end if not C then C = "" end if #A + #B + #C > MAX_LEN then return false end + if not pcall(WireLib.CheckRegex, A, B) then return false end return string.gsub(A,B,C) end, label = function(Out, A, B, C)