fix stack issues on CraftOS-PC

This commit is contained in:
2020-09-03 14:35:14 +01:00
parent ba7e30e850
commit 99a9d3de6e
4 changed files with 36 additions and 22 deletions

View File

@@ -125,9 +125,17 @@ local function toBytes(t, n)
return setmetatable(b, mt)
end
local function to_bytes(s)
local out = {}
for i = 1, #s do
out[i] = string.byte(s, i)
end
return out
end
local function digest(data)
local data = data or ""
data = type(data) == "table" and {upack(data)} or {tostring(data):byte(1,-1)}
data = type(data) == "table" and {upack(data)} or to_bytes(tostring(data))
data = preprocess(data)
local C = {upack(H)}
@@ -136,8 +144,8 @@ local function digest(data)
end
local function hmac(data, key)
local data = type(data) == "table" and {upack(data)} or {tostring(data):byte(1,-1)}
local key = type(key) == "table" and {upack(key)} or {tostring(key):byte(1,-1)}
local data = type(data) == "table" and {upack(data)} or to_bytes(tostring(data))
local key = type(key) == "table" and {upack(key)} or to_bytes(tostring(key))
local blocksize = 64

View File

@@ -644,9 +644,9 @@ function safe_json_serialize(x, prev)
elseif t == "boolean" then
return tostring(x)
elseif x == nil then
return nil
return "null"
else
return ("%q"):format(tostring(x))
return json.encode(tostring(x))
end
end
@@ -849,7 +849,8 @@ local function download_files(manifest_data, needed_files)
local h = assert(http.get(url, nil, true))
local x = h.readAll()
h.close()
if manifest_data.files[file] ~= hexize(sha256(x)) then error("hash mismatch on " .. file .. " - " .. url) end
local hexsha = hexize(sha256(x))
if manifest_data.files[file] ~= hexsha then error(("hash mismatch on %s %s (expected %s, got %s)"):format(file, url, manifest_data.files[file], hexsha)) end
fwrite(file, x)
count = count + 1
end)
@@ -1215,18 +1216,22 @@ local function run_with_sandbox()
print("Short hash", potatOS.build)
print("Full hash", potatOS.full_build)
local mfst = potatOS.registry.get "potatOS.current_manifest"
print("Counter", mfst.build)
print("Built at (local time)", os.date("%Y-%m-%d %X", mfst.timestamp))
print("Downloaded from", mfst.manifest_URL)
local verified = mfst.verified
if verified == nil then verified = "false [no signature]"
else
if verified == true then verified = "true"
if mfst then
print("Counter", mfst.build)
print("Built at (local time)", os.date("%Y-%m-%d %X", mfst.timestamp))
print("Downloaded from", mfst.manifest_URL)
local verified = mfst.verified
if verified == nil then verified = "false [no signature]"
else
verified = ("false %s"):format(tostring(mfst.verification_error))
if verified == true then verified = "true"
else
verified = ("false %s"):format(tostring(mfst.verification_error))
end
end
print("Signature verified:", verified)
else
print "Manifest not found in registry. Extended data unavailable."
end
print("Signature verified:", verified)
]],
["/rom/programs/id.lua"] = [[
print("ID", os.getComputerID())

View File

@@ -209,6 +209,7 @@ This incident has been reported.]], thing, category, category_descriptions[categ
end
return true
end
local check_safe = potatOS.check_safe
-- This flag is set... near the end of boot, or something... to enable code safety checking.
local boot_done = false
@@ -230,7 +231,7 @@ function load(code, file, ...)
return function() return ret end
end
if boot_done then
local ok, replace_with = potatOS.check_safe(code)
local ok, replace_with = check_safe(code)
if not ok then return replace_with end
end
if potatOS.registry.get "potatOS.protocol_epsilon" then
@@ -1788,14 +1789,14 @@ if potatOS.registry.get "potatOS.hide_peripherals" then
function peripheral.getNames() return {} end
end
if potatOS.registry.get "potatOS.immutable_global_scope" then
setmetatable(_G, { __newindex = function(_, x) error(("cannot set _G[%q] - _G is immutable"):format(tostring(x)), 0) end })
end
if meta then _G.meta = meta.new() end
if _G.textutilsprompt then textutils.prompt = _G.textutilsprompt end
if potatOS.registry.get "potatOS.immutable_global_scope" then
setmetatable(_G, { __newindex = function(_, x) error(("cannot set _G[%q] - _G is immutable"):format(tostring(x)), 0) end })
end
if process then
process.spawn(keyboard_shortcuts, "kbsd")
if http.websocket then process.spawn(skynet.listen, "skynetd") process.spawn(potatoNET, "systemd-potatod") end