From 38825335019f0b35e6be30e0fc2cfca090cefe21 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 01:54:21 +0100 Subject: [PATCH] Compare published BusyBox applet paths with installed package ownership --- tests/busybox/release-links.v | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/busybox/release-links.v diff --git a/tests/busybox/release-links.v b/tests/busybox/release-links.v new file mode 100644 index 0000000..69320a7 --- /dev/null +++ b/tests/busybox/release-links.v @@ -0,0 +1,83 @@ +// Print the BusyBox links from a reference image, optionally with their owners +// in a signed Vinix root previously checked by tests/installed-root.v. +module main + +import os + +fn release_links(archive string) ![]string { + listing := os.exec(['tar', '--numeric-owner', '--quoting-style=literal', '-tvf', archive]) + if listing.exit_code != 0 { + return error(listing.output.trim_space()) + } + mut links := map[string]string{} + for line in listing.output.split_into_lines() { + if !line.starts_with('l') || !line.contains(' -> ') { + continue + } + name := '/' + line.all_before(' -> ').all_after_last(' ').trim_string_left('./').trim_left('/') + target := line.all_after(' -> ') + links[name] = os.norm_path(if target.starts_with('/') { + target + } else { + os.join_path(os.dir(name), target) + }) + } + mut result := []string{} + for name, target in links { + if os.dir(name) !in ['/bin', '/sbin', '/usr/bin', '/usr/sbin'] { continue } + mut resolved := target + mut visited := map[string]bool{} + for (resolved in links) && !visited[resolved] { + visited[resolved] = true + resolved = links[resolved] + } + if resolved == '/bin/busybox' { result << name } + } + result.sort() + if result.len == 0 { return error('no BusyBox applet links in ${archive}') } + return result +} + +fn installed_owners(database string, paths []string) !map[string]string { + mut owners := map[string]string{} + for path in paths { owners[path] = '' } + for entry in os.ls(database)! { + if entry == 'ALPM_DB_VERSION' { continue } + dir := os.join_path(database, entry) + desc := '\n' + os.read_file(os.join_path(dir, 'desc'))! + if !desc.contains('\n%NAME%\n') { return error('missing package name in ${entry}') } + name := desc.all_after('\n%NAME%\n').all_before('\n') + files := os.read_file(os.join_path(dir, 'files'))! + if !files.starts_with('%FILES%\n') { return error('missing file list in ${entry}') } + for file in files.all_after('%FILES%\n').all_before('\n\n').split_into_lines() { + path := '/' + file + if path !in owners { continue } + if owners[path] != '' { return error('${path} is owned by both ${owners[path]} and ${name}') } + owners[path] = name + } + } + for path in paths { + if owners[path] == '' { return error('published BusyBox path has no package owner: ${path}') } + } + return owners +} + +fn main() { + if os.args.len !in [2, 3] { + eprintln('usage: release-links ROOT_TARBALL [INSTALLED_LOCAL_DB]') + exit(2) + } + links := release_links(os.args[1]) or { + eprintln(err) + exit(1) + } + if os.args.len == 3 { + owners := installed_owners(os.args[2], links) or { + eprintln(err) + exit(1) + } + for name in links { println('${name}\t${owners[name]}') } + } else { + for name in links { println(name) } + } +} -- 2.56.1