Skip to content

eBPF-based security platform

tools: run the binary put-shirudo-build is given, not PATH's

John Fastabend40fe852910e8
diff --git a/tools/backend/test/put-shirudo-build.expected b/tools/backend/test/put-shirudo-build.expected
index b89b153f..ead21c2a 100644
--- a/tools/backend/test/put-shirudo-build.expected
+++ b/tools/backend/test/put-shirudo-build.expected
@@ -4,6 +4,8 @@ first put: status 0
put-shirudo-build: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: already allowed
put-shirudo-build: cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc: allowed
again: status 0
+put-shirudo-build: eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee: allowed
+by its bare name: status 0
put-shirudo-build: 000000000000000000000000000000000000000000000000000000000000000 is neither a version_id nor a shirudo binary, nothing loaded
neither: status 1
put-shirudo-build: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA is neither a version_id nor a shirudo binary, nothing loaded
@@ -19,3 +21,4 @@ no argument: status 2
aaaa test-vm build
bbbb test-vm build
cccc
+eeee
diff --git a/tools/backend/test/put-shirudo-build.sh b/tools/backend/test/put-shirudo-build.sh
index cbba288d..605bc279 100644
--- a/tools/backend/test/put-shirudo-build.sh
+++ b/tools/backend/test/put-shirudo-build.sh
@@ -4,7 +4,8 @@
#
# tools/put-shirudo-build: allows builds given by version_id and by a
# binary that prints its own, once each; a build already allowed is left
-# as it is. Then what it refuses, each with a message and nothing loaded:
+# as it is; a binary named without a slash is the file of that name, not
+# the one PATH has. Then what it refuses, each with a message and nothing loaded:
# an argument that is neither, a binary that gives no version_id, a note
# with a control character and wrong usage.
@@ -37,6 +38,13 @@ chmod +x "$work/shirudo" "$work/broken"
run 'first put' "$helper" --note 'test-vm build' "$a" "$work/shirudo" "$a"
run 'again' "$helper" "$a" "$c"
+d=$(printf '%064d' 0 | tr 0 d)
+e=$(printf '%064d' 0 | tr 0 e)
+mkdir "$work/path"
+printf '#!/bin/sh\necho %s\n' "$d" >"$work/path/mine"
+printf '#!/bin/sh\necho %s\n' "$e" >"$work/mine"
+chmod +x "$work/path/mine" "$work/mine"
+(cd "$work" && PATH="$work/path:$PATH" && run 'by its bare name' "$helper" mine)
run 'neither' "$helper" "$(printf '%063d' 0)"
run 'upper' "$helper" "$(printf '%064d' 0 | tr 0 A)"
(cd "$work" && run 'no build from it' "$helper" ./broken)
diff --git a/tools/put-shirudo-build b/tools/put-shirudo-build
index e6764a9b..6fd88b59 100755
--- a/tools/put-shirudo-build
+++ b/tools/put-shirudo-build
@@ -62,7 +62,12 @@ version_id_of()
if is_version_id "$1"; then
printf '%s\n' "$1"
elif [ -f "$1" ] && [ -x "$1" ]; then
- id=$("$1" version --version-id 2>/dev/null) && is_version_id "$id" ||
+ # A name without a slash would run what PATH has, not this file.
+ case "$1" in
+ */*) binary=$1 ;;
+ *) binary=./$1 ;;
+ esac
+ id=$("$binary" version --version-id 2>/dev/null) && is_version_id "$id" ||
die "$1 does not give a version_id, nothing loaded"
printf '%s\n' "$id"
else