microcontroller: fix unsafe pattern usage (#620)

This commit is contained in:
fluxionary 2022-08-01 08:27:05 -07:00 committed by GitHub
parent c4f9336a26
commit da57a6214a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -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