Skip to content

petname 2.11 - Shell Script Security Improvements

Latest

Choose a tag to compare

@dustinkirkland dustinkirkland released this 15 Feb 04:16
· 15 commits to master since this release

petname 2.11 - Shell Script Security Improvements

Improved shell script security, robustness, and input validation.


πŸ”’ Security Enhancements

Input Validation

Added comprehensive parameter validation to prevent errors and improve security:

Numeric Validation:

# Before: Cryptic errors
$ petname --words abc
./petname: 131: Illegal number: abc

# After: Clear error message
$ petname --words abc
ERROR: words must be a positive integer, got: abc

Complexity Validation:

$ petname --complexity 5
ERROR: complexity must be 0 (small), 1 (medium), or 2 (large), got: 5

Directory Validation:

$ petname --dir /nonexistent
ERROR: directory does not exist: /nonexistent

Separator Length Limit:

$ petname --separator "$(python -c 'print("x" * 101)')"
ERROR: separator must be 100 characters or less

πŸ›‘οΈ Shell Script Best Practices

Quoted Variable Expansions

Fixed all unquoted variable expansions to prevent word splitting and glob expansion:

# Before (vulnerable to word splitting):
grep "pattern" $DIR/file.txt

# After (safe):
grep "pattern" "$DIR/file.txt"

Files Improved:

  • usr/bin/petname - All variable expansions quoted
  • debian/tests/checkwords - All variable expansions quoted

βœ… Improvements

Better Error Messages

  • Clear, actionable error messages
  • Explains what went wrong and what's expected
  • Helps users correct their mistakes

Parameter Validation

  • --words: Must be a positive integer
  • --letters: Must be a positive integer
  • --complexity: Must be 0, 1, or 2
  • --separator: Maximum 100 characters
  • --dir: Must exist and be readable

Robustness

  • Prevents cryptic shell errors
  • Validates input before processing
  • Graceful error handling
  • Better user experience

πŸ§ͺ Testing

Comprehensive test suite:

  • βœ… 10 security tests pass
  • βœ… All input validation working
  • βœ… Normal usage preserved
  • βœ… Error messages verified

πŸ“ Changes

usr/bin/petname:

  • Added numeric validation for --words and --letters
  • Added complexity validation (0, 1, or 2)
  • Added separator length limit (max 100 chars)
  • Added directory validation
  • Quoted all variable expansions
  • Improved error messages

debian/tests/checkwords:

  • Quoted all variable expansions
  • Improved shell script safety

debian/changelog:

  • Documented all improvements

πŸ“¦ Installation

# Snap
sudo snap install petname

# From source
git clone https://github.com/dustinkirkland/petname.git
cd petname
sudo make install

⚠️ Upgrade Recommendation

Priority: Medium - Recommended for improved robustness

Benefits:

  • Better error messages
  • Input validation prevents issues
  • Improved shell script safety
  • Better user experience

Breaking Changes: None - 100% backward compatible


πŸ™ Credits

Security improvements and shell script hardening by Claude Sonnet 4.5.

Report issues at: https://github.com/dustinkirkland/petname/issues