load vuln fixed, sudo fixed

This commit is contained in:
2026-02-23 22:43:12 -06:00
parent 6694711423
commit b015d5880a
6 changed files with 50 additions and 25 deletions

View File

@@ -5,14 +5,14 @@ kernel.vfs = vfs
vfs.mounts = {["$"] = "/"}
vfs.disks = kernel.disks
-- Metafile format (version 1)
-- File header: 1 byte = version (0x01)
-- Metafile format (version 2)
-- File header: 1 byte = version (0x02)
-- Per-entry:
-- 1 byte = name length
-- N bytes = name
-- 1 byte = entry type (0x00 = regular, 0x01 = symlink)
-- 1 byte = owner uid
-- 1 byte = group gid
-- 2 bytes = owner uid (little-endian uint16)
-- 2 bytes = group gid (little-endian uint16)
-- 2 bytes = perms (little-endian uint16)
-- bit 0 = world-write bit 1 = world-read
-- bit 2 = group-write bit 3 = group-read
@@ -24,12 +24,16 @@ vfs.disks = kernel.disks
-- 1 byte = cmeta length
-- N bytes = cmeta (for symlinks: the link target path)
--
-- Version 1:
-- 1 byte name len, N bytes name, 1 byte etype, 1 byte owner,
-- 1 byte group, 2 bytes perms (little-endian), 1 byte cmeta len, N bytes cmeta
--
-- Version 0:
-- No file header. Per-entry:
-- 1 byte name len, N bytes name, 1 byte owner, 1 byte group,
-- 1 byte perms (low 7 bits only), 1 byte cmeta len, N bytes cmeta
local META_VERSION = 0x01
local META_VERSION = 0x02
local function bit_is_set(num, bit)
return math.floor(num / (2 ^ bit)) % 2 == 1
@@ -41,8 +45,9 @@ local function parseMetafile(raw)
local p = 1
local version = 0
if raw:byte(1) == META_VERSION then
version = META_VERSION
local firstByte = raw:byte(1)
if firstByte == 0x02 or firstByte == 0x01 then
version = firstByte
p = 2
end
@@ -54,13 +59,22 @@ local function parseMetafile(raw)
local etype, owner, group, perms, cmeta
if version == META_VERSION then
if version == 0x02 then
-- v2: etype(1) + owner(2) + group(2) + perms(2) = 7 bytes
if p + 6 > #raw then break end
etype = raw:byte(p); p = p + 1
owner = raw:byte(p) + raw:byte(p+1) * 256; p = p + 2
group = raw:byte(p) + raw:byte(p+1) * 256; p = p + 2
perms = raw:byte(p) + raw:byte(p+1) * 256; p = p + 2
elseif version == 0x01 then
-- v1: etype(1) + owner(1) + group(1) + perms(2) = 5 bytes
if p + 4 > #raw then break end
etype = raw:byte(p); p = p + 1
owner = raw:byte(p); p = p + 1
group = raw:byte(p); p = p + 1
perms = raw:byte(p) + raw:byte(p+1) * 256; p = p + 2
else
-- v0: owner(1) + group(1) + perms(1) = 3 bytes
if p + 2 > #raw then break end
etype = 0x00
owner = raw:byte(p); p = p + 1
@@ -85,12 +99,16 @@ end
local function makeMetafile(meta)
local out = string.char(META_VERSION)
for name, m in pairs(meta) do
local plo = m.perms % 256
local phi = math.floor(m.perms / 256) % 256
local plo = m.perms % 256
local phi = math.floor(m.perms / 256) % 256
local olo = (m.owner or 0) % 256
local ohi = math.floor((m.owner or 0) / 256) % 256
local glo = (m.group or 0) % 256
local ghi = math.floor((m.group or 0) / 256) % 256
out = out
.. string.char(#name) .. name
.. string.char(m.etype or 0x00)
.. string.char(m.owner, m.group, plo, phi)
.. string.char(olo, ohi, glo, ghi, plo, phi)
.. string.char(#m.cmeta) .. m.cmeta
end
return out