fix: guard non-tty join picker; refuse whitespace PARTY_SOCKET_DIR
This commit is contained in:
parent
0d1b5ef796
commit
6cac86bb15
2 changed files with 42 additions and 0 deletions
15
party
15
party
|
|
@ -387,6 +387,15 @@ apply_party_perms_file() {
|
||||||
# directory.
|
# directory.
|
||||||
validate_socket_dir_parent() {
|
validate_socket_dir_parent() {
|
||||||
p="$PARTY_SOCKET_DIR"
|
p="$PARTY_SOCKET_DIR"
|
||||||
|
# Whitespace in the parent breaks every `for rec in $(roster_list)`
|
||||||
|
# walker and the unquoted paths embedded in tmux hook/status-right
|
||||||
|
# strings. Refuse at host time, where the dir is chosen, instead of
|
||||||
|
# corrupting quietly later.
|
||||||
|
case "$p" in
|
||||||
|
*[[:space:]]*)
|
||||||
|
echo "party: PARTY_SOCKET_DIR must not contain whitespace: $p" >&2
|
||||||
|
return 1 ;;
|
||||||
|
esac
|
||||||
if [ ! -d "$p" ]; then
|
if [ ! -d "$p" ]; then
|
||||||
echo "party: PARTY_SOCKET_DIR $p does not exist" >&2
|
echo "party: PARTY_SOCKET_DIR $p does not exist" >&2
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -530,6 +539,12 @@ pick_live_party() {
|
||||||
0) echo "party: no parties found on this host." >&2; return 1 ;;
|
0) echo "party: no parties found on this host." >&2; return 1 ;;
|
||||||
1) roster_read "$1"; return 0 ;;
|
1) roster_read "$1"; return 0 ;;
|
||||||
esac
|
esac
|
||||||
|
# 2+ parties need the interactive picker; without a tty read would
|
||||||
|
# EOF and set -e would kill us with no message.
|
||||||
|
if [ ! -t 0 ]; then
|
||||||
|
echo "party: multiple parties running; pass a name (see 'party list')." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
i=0
|
i=0
|
||||||
for r in "$@"; do
|
for r in "$@"; do
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
|
|
|
||||||
|
|
@ -109,3 +109,30 @@ setup() {
|
||||||
# to also confirm a foreign-uid PID is not preventing the result.
|
# to also confirm a foreign-uid PID is not preventing the result.
|
||||||
! is_party_alive 1 "$PARTY_TMP/no-such-sock"
|
! is_party_alive 1 "$PARTY_TMP/no-such-sock"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "validate_socket_dir_parent refuses whitespace in PARTY_SOCKET_DIR" {
|
||||||
|
spaced="$PARTY_TMP/with space"
|
||||||
|
mkdir -p "$spaced"
|
||||||
|
chmod 0700 "$spaced"
|
||||||
|
PARTY_SOCKET_DIR="$spaced" run validate_socket_dir_parent
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"whitespace"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "pick_live_party without a tty fails with guidance, not a silent death" {
|
||||||
|
# Two live-looking parties force the numbered picker; stdin is not a
|
||||||
|
# tty under bats, so the guard must fire before read.
|
||||||
|
stub="$PARTY_TMP/tmux-ok"
|
||||||
|
printf '#!/bin/sh\nexit 0\n' > "$stub"
|
||||||
|
chmod +x "$stub"
|
||||||
|
export PARTY_TMUX="$stub"
|
||||||
|
ensure_party_dir "$USER" one
|
||||||
|
ensure_party_dir "$USER" two
|
||||||
|
for n in one two; do
|
||||||
|
d="$PARTY_SOCKET_DIR/party-$USER:$n.d"
|
||||||
|
printf 'SERVER_PID=1\nGROUP=%s\n' "$(id -gn)" > "$d/roster"
|
||||||
|
done
|
||||||
|
run pick_live_party
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"pass a name"* ]]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue