pkg: Handle truncated sha256

Bug compat mode.

Some things produce truncated sha256 hashes in the status file. While
this bug is likely already fixed in opkg and it would not happen in
deployment, be ready to handle that bug anyway.
parent 60146a99
......@@ -814,6 +814,16 @@ function config_modified(file, hash)
hasher = md5
elseif len == 64 then
hasher = sha256
elseif len > 32 and len < 64 then
--[[
Something produces (produced?) truncated hashes in the status file.
Handle them. This is likely already fixed, but we don't want to
crash on system that still have these broken hashes around.
]]
hasher = function (content)
WARN("Truncated sha256 hash seen, using bug compat mode")
return sha256(content):sub(1, len)
end
else
error("Can not determine hash algorithm to use for hash " .. hash)
end
......
......@@ -703,6 +703,11 @@ function test_config_modified()
-- Case insensitive checks
assert_false(B.config_modified(file, "182171CCACFC32A9F684479509AC471A"))
assert_false(B.config_modified(file, "4F54362B30F53AE6862B11FF34D22A8D4510ED2B3E757B1F285DBD1033666E55"))
-- Truncated sha256
assert_false(B.config_modified(file, "4F54362B30F53AE6862B11FF34D22A8D4510ED2B3E757B1F285DBD10336"))
assert_false(B.config_modified(file, "4F54362B30F53AE6862B11FF34D22A8D4510ED2B3E757B1F"))
assert(B.config_modified(file, "5f54362b30f53ae6862b11ff34d22a8d4510ed2b3e757b1f285dbd1033666e"))
assert(B.config_modified(file, "5f54362b30f53ae6862b11ff34d22a8d4510ed2b3e757b1f285db"))
end
function setup()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment