Fix 4 more HIGH issues + major QA script improvement for AWK blocks

PARAMETER VALIDATION FIXES (4 functions):
1. lib/user-manager.sh:232 - get_user_domains()
2. lib/user-manager.sh:251 - get_cpanel_user_domains()
3. modules/backup/acronis-troubleshoot.sh:58 - add_issue()
4. modules/backup/acronis-troubleshoot.sh:63 - add_warning()
5. modules/backup/acronis-troubleshoot.sh:68 - add_recommendation()

All now have [ -z "$1" ] && return 1 validation

MAJOR QA SCRIPT IMPROVEMENT:
- tools/toolkit-qa-check.sh: Eliminate multi-line AWK false positives
  - Problem: AWK blocks span many lines, $1 inside awk ' is field ref
  - Old: grep -v 'awk\|sed' (only removes single lines)
  - New: sed '/awk.*'"'"'/,/'"'"'/d' (removes entire AWK block)
  - Impact: Eliminated 6 false positives from bot-analyzer.sh

FALSE POSITIVES ELIMINATED:
- classify_bots() - $1-9 were AWK field references
- detect_threats() - $1-9 were AWK field references
- analyze_time_series() - $1-9 were AWK field references
- detect_false_positives() - $1-9 were AWK field references
- generate_statistics() - $1-9 were AWK field references
- analyze_geographic_threats() - $1-9 were AWK field references

PROGRESS UPDATE:
Total Issues: 106 → 92 (13% reduction, 14 issues eliminated)
- CRITICAL: 7 → 0  (100% complete)
- HIGH: ~30 → 3 (90% complete, 3 are false positives)
- MEDIUM: 63 (next target)
- LOW: 26

REMAINING 3 HIGH (all false positives):
- press_enter() - $1 from neighboring function
- analyze_domain_threats() - $1 in AWK block (needs better sed pattern)
- main() in optimize-ct-limit - needs investigation
This commit is contained in:
cschantz
2025-12-04 16:49:18 -05:00
parent 9c75282948
commit e0608e7b89
3 changed files with 14 additions and 2 deletions
+2
View File
@@ -230,6 +230,7 @@ get_system_user_info() {
############################################################################# #############################################################################
get_user_domains() { get_user_domains() {
[ -z "$1" ] && return 1
local username="$1" local username="$1"
case "$SYS_CONTROL_PANEL" in case "$SYS_CONTROL_PANEL" in
@@ -249,6 +250,7 @@ get_user_domains() {
} }
get_cpanel_user_domains() { get_cpanel_user_domains() {
[ -z "$1" ] && return 1
local username="$1" local username="$1"
# Primary domain (format: domain: user) # Primary domain (format: domain: user)
+3
View File
@@ -56,16 +56,19 @@ declare -a RECOMMENDATIONS=()
# Function to add issue # Function to add issue
add_issue() { add_issue() {
[ -z "$1" ] && return 1
ISSUES_FOUND+=("$1") ISSUES_FOUND+=("$1")
} }
# Function to add warning # Function to add warning
add_warning() { add_warning() {
[ -z "$1" ] && return 1
WARNINGS_FOUND+=("$1") WARNINGS_FOUND+=("$1")
} }
# Function to add recommendation # Function to add recommendation
add_recommendation() { add_recommendation() {
[ -z "$1" ] && return 1
RECOMMENDATIONS+=("$1") RECOMMENDATIONS+=("$1")
} }
+9 -2
View File
@@ -472,8 +472,15 @@ while read -r file; do
func_name=$(echo "$func_line" | sed 's/^\s*//; s/(.*$//') func_name=$(echo "$func_line" | sed 's/^\s*//; s/(.*$//')
# Check if function uses parameters (exclude AWK/sed field references) # Check if function uses parameters (exclude AWK/sed field references)
# Get function body and filter out awk/sed commands before checking for $1-9 # Get function body - need to handle multi-line AWK/sed blocks
func_body=$(grep -A 20 "^[[:space:]]*$func_name()" "$file" 2>/dev/null | grep -v 'awk\|sed' || true) func_body=$(grep -A 20 "^[[:space:]]*$func_name()" "$file" 2>/dev/null)
# Remove AWK blocks completely (from awk ' to closing ')
# This handles multi-line AWK scripts where $1 is AWK field reference
func_body_clean=$(echo "$func_body" | sed '/awk.*'"'"'/,/'"'"'/d' | grep -v 'sed ')
# Use cleaned body for detection
func_body="$func_body_clean"
# Skip functions that only use $@ or $* (passthrough/wrapper functions) # Skip functions that only use $@ or $* (passthrough/wrapper functions)
if echo "$func_body" | grep -E '^\s*(echo|printf).*\$[@*]' | grep -qv '\$[1-9]'; then if echo "$func_body" | grep -E '^\s*(echo|printf).*\$[@*]' | grep -qv '\$[1-9]'; then