From da57a6214af9b23e50e319a5902b390e613725ee Mon Sep 17 00:00:00 2001 From: fluxionary <25628292+fluxionary@users.noreply.github.com> Date: Mon, 1 Aug 2022 08:27:05 -0700 Subject: [PATCH] microcontroller: fix unsafe pattern usage (#620) --- mesecons_microcontroller/init.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 2e11afa..05384da 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -332,7 +332,8 @@ yc.parse_get_eeprom_param = function(cond, starti) local addr while s ~= "" do s = string.sub(cond, i, i) - if string.find("0123456789", s) == nil or s == "" then + local b = s:byte() + if s == "" or 48 > b or b > 57 then addr = string.sub(cond, starti, i-1) -- i: last number i+1 after last number return addr, i end @@ -419,13 +420,16 @@ yc.command_sbi = function(params, eeprom, L, Lv) if status == nil then return nil, nil end - if string.find("ABCD", params[1])~=nil and #params[1]==1 then --is a port - if status == "1" then - Lv = yc.set_portstate (params[1], true, Lv) - else - Lv = yc.set_portstate (params[1], false, Lv) + if #params[1]==1 then + local b = params[1]:byte() + if 65 <= b and b <= 68 then -- is a port + if status == "1" then + Lv = yc.set_portstate (params[1], true, Lv) + else + Lv = yc.set_portstate (params[1], false, Lv) + end + return eeprom, Lv; end - return eeprom, Lv; end --is an eeprom address