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
9 changes: 4 additions & 5 deletions Cachyos/Scripts/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ print_warning() {

# Ensure log file is writable
ensure_log_file() {
if [ ! -f "$LOG_FILE" ]; then
if [[ ! -f "$LOG_FILE" ]]; then
sudo touch "$LOG_FILE" 2>/dev/null || touch "$LOG_FILE" 2>/dev/null
fi
sudo chmod 666 "$LOG_FILE" 2>/dev/null || chmod 666 "$LOG_FILE" 2>/dev/null
sudo chmod 644 "$LOG_FILE" 2>/dev/null || chmod 644 "$LOG_FILE" 2>/dev/null

if [ ! -w "$LOG_FILE" ]; then
if [[ ! -w "$LOG_FILE" ]]; then
echo "Warning: Cannot write to log file at $LOG_FILE, using temporary log"
LOG_FILE="/tmp/pkg-install-$(date +%s).log"
touch "$LOG_FILE"
LOG_FILE=$(mktemp /tmp/pkg-install-XXXXXX.log)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

While using mktemp is a great security improvement, it's important to handle potential failures and set secure permissions for the created log file. The style guide recommends checking for mktemp failure and setting permissions to 600 for temporary files (lines 638-639). This prevents potential information leakage if the log file contains sensitive data and the system's umask is permissive.

Suggested change
LOG_FILE=$(mktemp /tmp/pkg-install-XXXXXX.log)
LOG_FILE=$(mktemp /tmp/pkg-install-XXXXXX.log) || { print_error 'Failed to create temp log'; exit 1; }
chmod 600 "$LOG_FILE"
References
  1. The style guide for secure temporary files recommends checking for mktemp failure and setting file permissions to 600 to ensure only the owner can read/write. (link)

fi
Comment on lines +34 to 42
}

Expand Down
Loading