busy can properly exit, pattern can not inject code
This commit is contained in:
@@ -88,19 +88,23 @@ busy()
|
|||||||
esac
|
esac
|
||||||
done
|
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'
|
# 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
|
# Monitor /dev/urandom
|
||||||
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
|
(
|
||||||
|
hexdump -C < /dev/urandom | grep -iF --line-buffered "$pattern" | \
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
echo "$line"
|
echo "$line"
|
||||||
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||||
done
|
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