Repository navigation
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: abcComplexity Validation:
$ petname --complexity 5
ERROR: complexity must be 0 (small), 1 (medium), or 2 (large), got: 5Directory Validation:
$ petname --dir /nonexistent
ERROR: directory does not exist: /nonexistentSeparator 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 quoteddebian/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