From 4205efb6d084a2ef2cc2fff74e744550e13e4665 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Thu, 29 Jul 2021 10:11:43 -0400 Subject: [PATCH] Handle getting out-of-bounds bits in get_bit The binary state is not padded with zeroes, so they must be inferred. --- mesecons/util.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mesecons/util.lua b/mesecons/util.lua index 3cdeb64..846c995 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -163,8 +163,13 @@ function mesecon.getbinstate(nodename, states) end function mesecon.get_bit(binary,bit) - bit = bit or 1 - local c = binary:len()-(bit-1) + local len = binary:len() + if bit then + if bit > len then return false end + else + bit = 1 + end + local c = len-(bit-1) return binary:sub(c,c) == "1" end