minor changes, cleanup

pull/13/head
Simon Let 6 years ago
parent 55f8800a67
commit c1f6a3a3b0
  1. 1
      go.mod
  2. 2
      go.sum
  3. 14
      sanitize-history/resh-sanitize-history.go
  4. 3
      sanitizer_data/whitelist.txt

@ -4,6 +4,5 @@ go 1.12
require (
github.com/BurntSushi/toml v0.3.1
github.com/mattn/go-shellwords v1.0.5
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa
)

@ -1,6 +1,4 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/mattn/go-shellwords v1.0.5 h1:JhhFTIOslh5ZsPrpa3Wdg8bF0WI3b44EMblmU9wIsXc=
github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa h1:rW+Lu6281ed/4XGuVIa4/YebTRNvoUJlfJ44ktEVwZk=
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa/go.mod h1:2rx5KE5FLD0HRfkkpyn8JwbVLBdhgeiOb2D2D9LLKM4=

@ -38,8 +38,8 @@ func main() {
showVersion := flag.Bool("version", false, "Show version and exit")
showRevision := flag.Bool("revision", false, "Show git revision and exit")
trimHashes := flag.Int("trim-hashes", 12, "Trim hashes to N characters (default: 12), 0 turns off trimming")
outputPath := flag.String("output", "", "Output file")
trimHashes := flag.Int("trim-hashes", 12, "Trim hashes to N characters, '0' turns off trimming")
outputPath := flag.String("output", "", "Output file (default: use stdout)")
flag.Parse()
@ -177,11 +177,13 @@ func (s *sanitizer) sanitizeRecord(record *common.Record) error {
}
func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) {
const optionEndingChars = "=;)"
const optionAllowedChars = "-_"
sanCmdLine := ""
buff := ""
// simple options shouldn't be sanitized
// 1) whitespace 2) "-" or "--" 3) letters, digits, "-", "_" 4) ending whitespace or "="
// 1) whitespace 2) "-" or "--" 3) letters, digits, "-", "_" 4) ending whitespace or any of "=;)"
var optionDetected bool
prevR3 := ' '
@ -190,7 +192,7 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) {
for _, r := range cmdLine {
switch optionDetected {
case true:
if unicode.IsSpace(r) || r == '=' || r == ';' {
if unicode.IsSpace(r) || strings.ContainsRune(optionEndingChars, r) {
// whitespace, "=" or ";" ends the option
// => add option unsanitized
optionDetected = false
@ -199,7 +201,8 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) {
buff = ""
}
sanCmdLine += string(r)
} else if unicode.IsLetter(r) == false && unicode.IsDigit(r) == false && r != '-' && r != '_' {
} else if unicode.IsLetter(r) == false && unicode.IsDigit(r) == false &&
strings.ContainsRune(optionAllowedChars, r) == false {
// r is not any of allowed chars for an option: letter, digit, "-" or "_"
// => sanitize
if len(buff) > 0 {
@ -217,6 +220,7 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) {
case false:
// split command on all non-letter and non-digit characters
if unicode.IsLetter(r) == false && unicode.IsDigit(r) == false {
// TODO: decide if we want to split on tokens
// split token
if len(buff) > 0 {
sanToken, err := s.sanitizeCmdToken(buff)

@ -104,6 +104,7 @@ com
combinedeltarpm
comm
command
convert
coredumpctl
cp
cpgr
@ -781,6 +782,7 @@ view
vigr
vipw
visudo
vlc
vmstat
w
wait
@ -812,6 +814,7 @@ xzfgrep
xzgrep
xzless
xzmore
yaourt
yes
ypdomainname
yum

Loading…
Cancel
Save