From c1f6a3a3b050de905aee4537b925a736ebd584a8 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Sun, 11 Aug 2019 18:08:34 +0200 Subject: [PATCH] minor changes, cleanup --- go.mod | 1 - go.sum | 2 -- sanitize-history/resh-sanitize-history.go | 14 +++++++++----- sanitizer_data/whitelist.txt | 3 +++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 9ff85f1..28d5ece 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 629918a..72fef1f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/sanitize-history/resh-sanitize-history.go b/sanitize-history/resh-sanitize-history.go index 9dbe9ea..c2bb51a 100644 --- a/sanitize-history/resh-sanitize-history.go +++ b/sanitize-history/resh-sanitize-history.go @@ -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) diff --git a/sanitizer_data/whitelist.txt b/sanitizer_data/whitelist.txt index e765f43..74b4625 100644 --- a/sanitizer_data/whitelist.txt +++ b/sanitizer_data/whitelist.txt @@ -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