busy can properly exit, pattern can not inject code
This commit is contained in:
@@ -88,19 +88,23 @@ busy()
|
||||
esac
|
||||
done
|
||||
|
||||
# If a pattern was provided as a positional argument (e.g., 'busy "ff 00"'),
|
||||
# it is captured here.
|
||||
[[ -n "$1" ]] && pattern="$1"
|
||||
|
||||
# Convert milliseconds to seconds for 'sleep'
|
||||
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
|
||||
local delay_s=$(awk "BEGIN{
|
||||
printf \"%.3f\", $delay_ms / 1000 }")
|
||||
|
||||
# Monitor /dev/urandom
|
||||
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
|
||||
while read -r line; do
|
||||
echo "$line"
|
||||
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||
done
|
||||
(
|
||||
hexdump -C < /dev/urandom | grep -iF --line-buffered "$pattern" | \
|
||||
while read -r line; do
|
||||
echo "$line"
|
||||
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||
done
|
||||
) & local sub_pid=$!
|
||||
|
||||
IFS= read -r -n 1 -s _ </dev/tty
|
||||
kill -- -"$sub_pid" 2>/dev/null || kill "$sub_pid" 2>/dev/null
|
||||
wait "$sub_pid" 2>/dev/null
|
||||
return 0
|
||||
}
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user