Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions scripts/discover-servers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ for f in "$servers_dir"/*.json; do

pid=$(jq -r '.pid' "$f" 2>/dev/null) || continue

# Clean up stale entries
if ! kill -0 "$pid" 2>/dev/null; then
rm -f "$f"
continue
# Clean up stale entries. Under MSYS/Cygwin, accept either a Windows-native
# process lookup or `kill -0` so we handle both Windows and Bash-owned PIDs.
if [[ "$OSTYPE" == msys* || "$OSTYPE" == cygwin* ]]; then
if ! powershell.exe -NoProfile -Command "Get-Process -Id $pid -ErrorAction SilentlyContinue | Out-Null; if (\$?) { exit 0 } else { exit 1 }" \
&& ! kill -0 "$pid" 2>/dev/null; then
Comment on lines +27 to +29

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If powershell.exe is unavailable on a given MSYS/Cygwin setup, this will emit a "command not found" error to stderr on every iteration (even though the kill -0 fallback still works). Consider checking command -v powershell.exe first (or redirecting its stderr) to keep output clean and avoid noisy logs.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Comment on lines +27 to +29

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$pid is interpolated directly into the PowerShell -Command string. Since the PID is read from a JSON file in the registry directory, a malformed or tampered .pid value could break the PowerShell command or be used for command injection. Please validate that pid is strictly numeric before using it, and pass it to PowerShell as an argument/parameter (instead of string interpolation) so it can’t alter the command text.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

rm -f "$f"
continue
fi
else
if ! kill -0 "$pid" 2>/dev/null; then
Comment thread
daanzu marked this conversation as resolved.
rm -f "$f"
continue
fi
fi

entry=$(jq '.' "$f" 2>/dev/null) || continue
Expand Down
Loading