1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-08 21:59:16 +00:00

More secure deletion and cannot delete path

This commit is contained in:
Tw93
2025-11-14 11:38:25 +08:00
parent ddef8c4bc0
commit 4f8f31444d
5 changed files with 139 additions and 10 deletions

View File

@@ -450,10 +450,17 @@ start_cleanup() {
SYSTEM_CLEAN=true
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access granted"
echo ""
# Start sudo keepalive with error handling
# Start sudo keepalive with robust parent checking
# Store parent PID to ensure keepalive exits if parent dies
parent_pid=$$
(
local retry_count=0
while true; do
# Check if parent process still exists first
if ! kill -0 "$parent_pid" 2> /dev/null; then
exit 0
fi
if ! sudo -n true 2> /dev/null; then
((retry_count++))
if [[ $retry_count -ge 3 ]]; then
@@ -464,7 +471,6 @@ start_cleanup() {
fi
retry_count=0
sleep 30
kill -0 "$$" 2> /dev/null || exit
done
) 2> /dev/null &
SUDO_KEEPALIVE_PID=$!

View File

@@ -452,8 +452,22 @@ uninstall_applications() {
read -p " Force quit $app_name? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
pkill -f "$app_path" 2> /dev/null || true
sleep 2
# Retry kill operation with verification to avoid TOCTOU
local retry=0
while [[ $retry -lt 3 ]]; do
pkill -f "$app_path" 2> /dev/null || true
sleep 1
# Verify app was killed
if ! pgrep -f "$app_path" > /dev/null 2>&1; then
break
fi
((retry++))
done
# Final check
if pgrep -f "$app_path" > /dev/null 2>&1; then
log_warning "Failed to quit $app_name after $retry attempts"
fi
else
echo -e " ${BLUE}${ICON_EMPTY}${NC} Skipped $app_name"
continue