From d18c935db2a4dd20a2cd7c1820b32603de3348f5 Mon Sep 17 00:00:00 2001 From: gamemanj Date: Tue, 28 Mar 2017 10:30:01 +0100 Subject: [PATCH] Fix bug in cdlib where names could be accepted yet truncated. --- cdlib.lua | 1 + oc/ecomponents/base | 3 ++- oc/uc-rsctl.lua | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cdlib.lua b/cdlib.lua index 1b19193..99e2315 100644 --- a/cdlib.lua +++ b/cdlib.lua @@ -18,6 +18,7 @@ local function decodeName(message) if message:len() < 2 then return end local nlen = message:byte(1) + 1 local fnam = message:sub(2, nlen + 1) + if fnam:len() < nlen then return end return fnam, message:sub(nlen + 2) end diff --git a/oc/ecomponents/base b/oc/ecomponents/base index fed8307..57a62f6 100644 --- a/oc/ecomponents/base +++ b/oc/ecomponents/base @@ -27,7 +27,8 @@ TX.open(4957) TB=TX.broadcast function TN(m) if#m<2then return end - local n=m:byte(1)+2return m:sub(2,n),m:sub(n+1) + local n,t=m:byte(1)+2t=m:sub(n+1) + if#t>=n then return m:sub(2,n),m:sub(n+1)end end function TR(m) local h,s,m,d=m:byte(),TN(m:sub(2)) diff --git a/oc/uc-rsctl.lua b/oc/uc-rsctl.lua index 33dd3b0..21158fa 100644 --- a/oc/uc-rsctl.lua +++ b/oc/uc-rsctl.lua @@ -2,7 +2,8 @@ S,C,TC=string,component,"copper" function CG(n)return C.proxy(C.list(n)())end TH,TX=CG("eeprom").getLabel(),CG("modem")TX.open(4957)TB=TX.broadcast function TN(m)if#m<2then return end -local n=m:byte(1)+2return m:sub(2,n),m:sub(n+1)end +local n,t=m:byte(1)+2t=m:sub(n+1)if#t>=n then return m:sub(2,n),m:sub(n+1)end +end function TR(m)local h,s,m,d=m:byte(),TN(m:sub(2))if s then d,m=TN(m)if d then return s,d,m