From f78fe7dde50ec43eafd56c2d32adf25d823407e9 Mon Sep 17 00:00:00 2001 From: Michael Cohen Date: Tue, 17 Sep 2019 11:34:45 +1000 Subject: [PATCH] Various changes for fixing static analysis comments. (#72) --- api/api.go | 2 -- api/auth.go | 13 ------------- api/handlers.go | 2 -- artifacts/artifacts_test.go | 4 ---- artifacts/assets/ab0x.go | 4 ++-- artifacts/obfuscation.go | 2 +- bin/fuse.go | 4 ---- bin/report.go | 12 ++++-------- crypto/simple.go | 1 - file_store/compress.go | 5 ++--- file_store/csv/writer.go | 3 --- file_store/file_store.go | 6 +++--- flows/artifacts.go | 3 +++ flows/proto/flows.pb.go | 2 +- flows/proto/flows.proto | 2 +- go.mod | 1 + go.sum | 10 ++++++++++ reporting/container.go | 14 +++++--------- reporting/expand.go | 4 ++-- reporting/report.go | 12 ++---------- reporting/text_expander.go | 4 ++-- server/comms.go | 10 +++++----- services/ddclient.go | 5 +++++ staticcheck.conf | 8 ++++---- vql/common/fifo.go | 15 +-------------- vql/filesystem/raw_registry.go | 19 +++++++++---------- vql/filesystem/zip.go | 19 +++++++++---------- vql/networking/uploader.go | 7 +++---- vql/parsers/ntfs.go | 6 +++--- vql/parsers/ole.go | 3 +-- 30 files changed, 79 insertions(+), 123 deletions(-) diff --git a/api/api.go b/api/api.go index 1b3f2ffaa9f..94fc3c371a9 100644 --- a/api/api.go +++ b/api/api.go @@ -59,7 +59,6 @@ type ApiServer struct { func (self *ApiServer) CancelFlow( ctx context.Context, in *api_proto.ApiFlowRequest) (*api_proto.StartFlowResponse, error) { - result := &api_proto.StartFlowResponse{} user := GetGRPCUserInfo(ctx).Name // Empty users are called internally. @@ -95,7 +94,6 @@ func (self *ApiServer) CancelFlow( func (self *ApiServer) ArchiveFlow( ctx context.Context, in *api_proto.ApiFlowRequest) (*api_proto.StartFlowResponse, error) { - result := &api_proto.StartFlowResponse{} user := GetGRPCUserInfo(ctx).Name // Empty users are called internally. diff --git a/api/auth.go b/api/auth.go index 58810b5aa8c..cdaf7ffc05b 100644 --- a/api/auth.go +++ b/api/auth.go @@ -96,19 +96,6 @@ func IsUserApprovedForClient( return true } -func getClientApprovalForUser( - config *config_proto.Config, - md *metadata.MD, - client_id string) *api_proto.ApprovalList { - result := api_proto.ApprovalList{ - Items: []*api_proto.Approval{ - {Reason: "test"}, - }, - } - - return &result -} - func GetGRPCUserInfo(ctx context.Context) *api_proto.VelociraptorUser { result := &api_proto.VelociraptorUser{} diff --git a/api/handlers.go b/api/handlers.go index 420ecef3f84..e77d8c78215 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -32,7 +32,6 @@ import ( type statusRecorder struct { http.ResponseWriter http.Flusher - http.CloseNotifier status int error []byte } @@ -73,7 +72,6 @@ func GetLoggingHandler(config_obj *config_proto.Config) func(http.Handler) http. rec := &statusRecorder{ w, w.(http.Flusher), - w.(http.CloseNotifier), 200, nil} defer func() { if rec.status == 500 { diff --git a/artifacts/artifacts_test.go b/artifacts/artifacts_test.go index 563379229b5..daf2567177d 100644 --- a/artifacts/artifacts_test.go +++ b/artifacts/artifacts_test.go @@ -18,7 +18,6 @@ package artifacts import ( - "flag" "testing" "github.com/stretchr/testify/assert" @@ -26,9 +25,6 @@ import ( ) var ( - environment = flag.String("test.env", "", - "The name of the test environment.") - // Artifacts 1 and 2 are invalid: cyclic artifact1 = ` name: Artifact1 diff --git a/artifacts/assets/ab0x.go b/artifacts/assets/ab0x.go index 8f0415bfec9..af8c4f9041f 100644 --- a/artifacts/assets/ab0x.go +++ b/artifacts/assets/ab0x.go @@ -1,5 +1,5 @@ -// Code generated by fileb0x at "2019-09-15 22:48:40.932170631 +1000 AEST m=+0.173162629" from config file "b0x.yaml" DO NOT EDIT. -// modification hash(e589065fbf629ae8235cc175264d0819.57a51d2c6575595a5e61a0db12c9b9e7) +// Code generated by fileb0x at "2019-09-16 21:34:38.579926524 +1000 AEST m=+0.242714313" from config file "b0x.yaml" DO NOT EDIT. +// modification hash(95095507b1de752bed6f1c17a0d9623d.57a51d2c6575595a5e61a0db12c9b9e7) package assets diff --git a/artifacts/obfuscation.go b/artifacts/obfuscation.go index 2522a946d19..442f237f864 100644 --- a/artifacts/obfuscation.go +++ b/artifacts/obfuscation.go @@ -51,7 +51,7 @@ func Obfuscate( return nil } -var obfuscated_item = regexp.MustCompile("\\$[a-fA-F0-9]+") +var obfuscated_item = regexp.MustCompile(`\$[a-fA-F0-9]+`) func DeobfuscateString(config_obj *config_proto.Config, in string) string { if config_obj.Frontend.DoNotCompressArtifacts { diff --git a/bin/fuse.go b/bin/fuse.go index 9de2ca9d552..d4e60feeea5 100644 --- a/bin/fuse.go +++ b/bin/fuse.go @@ -23,7 +23,6 @@ import ( api_proto "www.velocidex.com/golang/velociraptor/api/proto" config_proto "www.velocidex.com/golang/velociraptor/config/proto" "www.velocidex.com/golang/velociraptor/datastore" - "www.velocidex.com/golang/velociraptor/file_store" flows_proto "www.velocidex.com/golang/velociraptor/flows/proto" "www.velocidex.com/golang/velociraptor/grpc_client" "www.velocidex.com/golang/velociraptor/logging" @@ -48,8 +47,6 @@ type VFSFs struct { // Cache directory listings. cache map[string][]*api.FileInfoRow logger *logging.LogContext - - file_store *file_store.DirectoryFileStore } func (self *VFSFs) fetchDir(vfs_name string) ([]*api.FileInfoRow, error) { @@ -322,7 +319,6 @@ func (self *VFSFileReader) Read(dest []byte, off int64) ( return nil, fuse.ENOENT } - dest = response.Data return fuse.ReadResultData(response.Data), fuse.OK } diff --git a/bin/report.go b/bin/report.go index 6731ed4827e..3d6cc6a46bf 100644 --- a/bin/report.go +++ b/bin/report.go @@ -5,7 +5,6 @@ import ( "time" kingpin "gopkg.in/alecthomas/kingpin.v2" - artifacts_proto "www.velocidex.com/golang/velociraptor/artifacts/proto" "www.velocidex.com/golang/velociraptor/reporting" ) @@ -35,17 +34,14 @@ func doDailyMonitoring() { getRepository(config_obj) - parameters := []*artifacts_proto.ArtifactParameter{} - for k, v := range *env_map { - parameters = append(parameters, &artifacts_proto.ArtifactParameter{ - Name: k, Default: v, - }) - } - template_engine, err := reporting.NewTextTemplateEngine( config_obj, *report_command_daily_monitoring_artifact) kingpin.FatalIfError(err, "Generating report") + for k, v := range *env_map { + template_engine.SetEnv(k, v) + } + ts, err := time.Parse("2006-01-02", *report_command_daily_monitoring_day_name) kingpin.FatalIfError(err, "Invalid day name (e.g. 2019-02-28)") diff --git a/crypto/simple.go b/crypto/simple.go index a0c71ee9819..66f7ff28529 100644 --- a/crypto/simple.go +++ b/crypto/simple.go @@ -18,7 +18,6 @@ import ( type Obfuscator struct { mu sync.Mutex key []byte - iv []byte crypter cipher.Block } diff --git a/file_store/compress.go b/file_store/compress.go index a113eb12e86..f9a517bd0e7 100644 --- a/file_store/compress.go +++ b/file_store/compress.go @@ -18,7 +18,6 @@ package file_store import ( - "errors" "fmt" "io" "os" @@ -38,9 +37,9 @@ func (self *SeekableGzip) Seek(offset int64, whence int) (int64, error) { } } - return 0, errors.New(fmt.Sprintf( + return 0, fmt.Errorf( "Seeking to %v (%v) not supported on compressed files.", - offset, whence)) + offset, whence) } func (self SeekableGzip) Stat() (os.FileInfo, error) { diff --git a/file_store/csv/writer.go b/file_store/csv/writer.go index 7fb50de7b70..89a60db7240 100644 --- a/file_store/csv/writer.go +++ b/file_store/csv/writer.go @@ -23,9 +23,6 @@ import ( var ( number_regex = regexp.MustCompile( `^(?P[-+]?\d*\.?\d+([eE][-+]?\d+)?)$`) - integer_regex = regexp.MustCompile( - "^[+-]?[0-9]+$") - protected_prefix = regexp.MustCompile( `^( |\{|\[|true|false|base64:)`) ) diff --git a/file_store/file_store.go b/file_store/file_store.go index c9f7a479e8d..65d89829be9 100644 --- a/file_store/file_store.go +++ b/file_store/file_store.go @@ -204,9 +204,9 @@ func (self *DirectoryFileStore) Walk(root string, walkFn filepath.WalkFunc) erro path := self.FilenameToFileStorePath(root) return filepath.Walk(path, func(path string, info os.FileInfo, err error) error { - filename, err := self.FileStorePathToFilename(path) - if err != nil { - return err + filename, err_1 := self.FileStorePathToFilename(path) + if err_1 != nil { + return err_1 } return walkFn(filename, &FileStoreFileInfo{info, path, nil}, err) diff --git a/flows/artifacts.go b/flows/artifacts.go index 1df525a9b28..b0d7cbb463e 100644 --- a/flows/artifacts.go +++ b/flows/artifacts.go @@ -182,6 +182,9 @@ func (self *ArtifactCollector) ProcessMessage( hunt.Stats.TotalClientsWithResults++ return nil }) + if err != nil { + return err + } } return flow_obj.Complete(config_obj) diff --git a/flows/proto/flows.pb.go b/flows/proto/flows.pb.go index 1f64863dddb..dc7a789786c 100644 --- a/flows/proto/flows.pb.go +++ b/flows/proto/flows.pb.go @@ -172,7 +172,7 @@ type FlowContext struct { NextProcessedRequest uint64 `protobuf:"varint,9,opt,name=next_processed_request,json=nextProcessedRequest,proto3" json:"next_processed_request,omitempty"` OutstandingRequests uint64 `protobuf:"varint,11,opt,name=outstanding_requests,json=outstandingRequests,proto3" json:"outstanding_requests,omitempty"` TotalResults uint64 `protobuf:"varint,18,opt,name=total_results,json=totalResults,proto3" json:"total_results,omitempty"` - // Deprecated: Uploads are now stored in a csv file. + // Uploads are now permanently stored in a csv file. UploadedFiles []*UploadedFileInfo `protobuf:"bytes,24,rep,name=uploaded_files,json=uploadedFiles,proto3" json:"uploaded_files,omitempty"` TotalUploadedFiles uint64 `protobuf:"varint,23,opt,name=total_uploaded_files,json=totalUploadedFiles,proto3" json:"total_uploaded_files,omitempty"` TotalExpectedUploadedBytes uint64 `protobuf:"varint,25,opt,name=total_expected_uploaded_bytes,json=totalExpectedUploadedBytes,proto3" json:"total_expected_uploaded_bytes,omitempty"` diff --git a/flows/proto/flows.proto b/flows/proto/flows.proto index c10c0653ff6..8bce19d88bd 100644 --- a/flows/proto/flows.proto +++ b/flows/proto/flows.proto @@ -45,7 +45,7 @@ message FlowContext { description: "The total number of results in the flow's result collection", }]; - // Deprecated: Uploads are now stored in a csv file. + // Uploads are now permanently stored in a csv file. repeated uploaded_file_info uploaded_files = 24 [(sem_type) = { description: "A list of files uploaded as part of the flow." }]; diff --git a/go.mod b/go.mod index 9e5fc68b70d..0e78cc2acf0 100644 --- a/go.mod +++ b/go.mod @@ -91,6 +91,7 @@ require ( gopkg.in/gomail.v2 v2.0.0-20150902115704-41f357289737 gopkg.in/olivere/elastic.v5 v5.0.81 gopkg.in/russross/blackfriday.v2 v2.0.1 + honnef.co/go/tools v0.0.1-2019.2.3 // indirect www.velocidex.com/golang/evtx v0.0.0-20190210013513-b45fe1505163 www.velocidex.com/golang/go-ntfs v0.0.0-20190915152010-a30b0daf7439 www.velocidex.com/golang/go-pe v0.1.0 diff --git a/go.sum b/go.sum index 83e6a13e4a0..59a2ef0027c 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= @@ -162,6 +163,7 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -247,6 +249,7 @@ github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 h1:J4AOUcOh/t1XbQcJfkEqhzgvMJ2tDxdCVvmHxW5QXao= github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7/go.mod h1:Oz4y6ImuOQZxynhbSXk7btjEfNBtGlj2dcaOvXl2FSM= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -287,6 +290,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7 h1:0hQKqeLdqlt5iIwVOBErRisrHJAN57yOiPRQItI20fU= @@ -300,6 +304,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -360,6 +365,8 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190624190245-7f2218787638 h1:uIfBkD8gLczr4XDgYpt/qJYds2YJwZRNw4zs7wSnNhk= golang.org/x/tools v0.0.0-20190624190245-7f2218787638/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -390,6 +397,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/gomail.v2 v2.0.0-20150902115704-41f357289737 h1:NvePS/smRcFQ4bMtTddFtknbGCtoBkJxGmpSpVRafCc= gopkg.in/gomail.v2 v2.0.0-20150902115704-41f357289737/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/olivere/elastic.v5 v5.0.81 h1:21Vu9RMT2qXVLqXINtiOhwVPYz/87+Omsxh/Re+gK4k= @@ -403,6 +411,8 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= www.velocidex.com/golang/evtx v0.0.0-20190210013513-b45fe1505163 h1:V7V2q7jlyUaJMdYMbugnIJobhCmOCMyU8zxhogVU51U= www.velocidex.com/golang/evtx v0.0.0-20190210013513-b45fe1505163/go.mod h1:6EBI36C3s9YR484Vfw7ZNQywHpDv/XHSaNbFF24xejs= diff --git a/reporting/container.go b/reporting/container.go index 909e1d0b613..71b6661cd5f 100644 --- a/reporting/container.go +++ b/reporting/container.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path" "sync" @@ -57,8 +56,6 @@ func (self *Container) DumpRowsIntoContainer( scope *vfilter.Scope, query *actions_proto.VQLRequest) error { - writer := ioutil.Discard - if len(output_rows) == 0 { return nil } @@ -67,11 +64,10 @@ func (self *Container) DumpRowsIntoContainer( defer self.Unlock() sanitized_name := datastore.SanitizeString(query.Name + ".csv") - container_writer, err := self.zip.Create(string(sanitized_name)) + writer, err := self.zip.Create(string(sanitized_name)) if err != nil { return err } - writer = container_writer csv_writer, err := csv.GetCSVWriter(scope, &StdoutWrapper{writer}) if err != nil { @@ -85,24 +81,24 @@ func (self *Container) DumpRowsIntoContainer( csv_writer.Close() sanitized_name = datastore.SanitizeString(query.Name + ".json") - container_writer, err = self.zip.Create(string(sanitized_name)) + writer, err = self.zip.Create(string(sanitized_name)) if err != nil { return err } - err = json.NewEncoder(container_writer).Encode(output_rows) + err = json.NewEncoder(writer).Encode(output_rows) if err != nil { return err } // Format the description. sanitized_name = datastore.SanitizeString(query.Name + ".txt") - container_writer, err = self.zip.Create(string(sanitized_name)) + writer, err = self.zip.Create(string(sanitized_name)) if err != nil { return err } - fmt.Fprintf(container_writer, "# %s\n\n%s", query.Name, + fmt.Fprintf(writer, "# %s\n\n%s", query.Name, FormatDescription(config_obj, query.Description, output_rows)) return nil diff --git a/reporting/expand.go b/reporting/expand.go index 75c1df97d64..5072f589a62 100644 --- a/reporting/expand.go +++ b/reporting/expand.go @@ -90,7 +90,7 @@ func FormatDescription( return description } - return string(buffer.Bytes()) + return buffer.String() } func (self *Expansions) DocFrom(artifact string) string { @@ -132,5 +132,5 @@ func (self *Expansions) Query(queries ...string) string { table.Render() } - return string(result.Bytes()) + return result.String() } diff --git a/reporting/report.go b/reporting/report.go index 8a8127d93bc..6843a86fe9c 100644 --- a/reporting/report.go +++ b/reporting/report.go @@ -1,7 +1,6 @@ package reporting import ( - "errors" "fmt" "strings" @@ -13,13 +12,6 @@ import ( "www.velocidex.com/golang/vfilter" ) -var ( - valid_report_types = []string{ - "MONITORING_DAILY", "CLIENT", - "CLIENT_EVENT", "SERVER_EVENT", "HUNT", - } -) - // An expander is presented to the go templates to implement template // operations. type TemplateEngine interface { @@ -282,8 +274,8 @@ func newBaseTemplateEngine( artifact, pres := repository.Get(artifact_name) if !pres { - return nil, errors.New( - fmt.Sprintf("Artifact %v not known.", artifact_name)) + return nil, fmt.Errorf( + "Artifact %v not known.", artifact_name) } env := vfilter.NewDict(). diff --git a/reporting/text_expander.go b/reporting/text_expander.go index 721f881892a..f3443779aff 100644 --- a/reporting/text_expander.go +++ b/reporting/text_expander.go @@ -29,7 +29,7 @@ func (self *TextTemplateEngine) Execute(template_string string) (string, error) return "", err } - return string(buffer.Bytes()), nil + return buffer.String(), nil } func (self *TextTemplateEngine) Query(queries ...string) []vfilter.Row { @@ -105,7 +105,7 @@ func (self *TextTemplateEngine) Table(values ...interface{}) string { table.Render() - return string(buffer.Bytes()) + return buffer.String() } func NewTextTemplateEngine(config_obj *config_proto.Config, diff --git a/server/comms.go b/server/comms.go index d969dd4d63e..e506ebe964b 100644 --- a/server/comms.go +++ b/server/comms.go @@ -434,6 +434,8 @@ func reader(config_obj *config_proto.Config, server_obj *Server) http.Handler { logger := logging.GetLogger(config_obj, &logging.FrontendComponent) return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + ctx := req.Context() + flusher, ok := w.(http.Flusher) if !ok { panic("http handler is not a flusher") @@ -521,13 +523,11 @@ func reader(config_obj *config_proto.Config, server_obj *Server) http.Handler { return } - // Figure out when the client drops the connection so - // we can exit. - close_notify := w.(http.CloseNotifier).CloseNotify() - for { select { - case <-close_notify: + // Figure out when the client drops the + // connection so we can exit. + case <-ctx.Done(): return case quit := <-notification: diff --git a/services/ddclient.go b/services/ddclient.go index f3bc511b2bf..f8887b66537 100644 --- a/services/ddclient.go +++ b/services/ddclient.go @@ -5,6 +5,7 @@ package services import ( "context" "fmt" + "io" "io/ioutil" "net" "net/http" @@ -129,6 +130,10 @@ func GetExternalIp() (string, error) { ip, err := ioutil.ReadAll(resp.Body) result := strings.TrimSpace(string(ip)) + if err != nil && err != io.EOF { + return result, err + } + return result, nil } diff --git a/staticcheck.conf b/staticcheck.conf index 758b89899ec..f8689f0ac1f 100644 --- a/staticcheck.conf +++ b/staticcheck.conf @@ -1,12 +1,12 @@ checks = ["all", + # error strings should not be capitalized (ST1005) + "-ST1005", + # receiver name should be a reflection of its identity "-ST1006", + # should not use underscores in Go names "-ST1003", # at least one file in a package should have a package comment "-ST1000", - - # should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) - "-S1028", - # the surrounding loop is unconditionally terminated "-SA4004", ] \ No newline at end of file diff --git a/vql/common/fifo.go b/vql/common/fifo.go index 129a4f3c9a4..0194f7f0f85 100644 --- a/vql/common/fifo.go +++ b/vql/common/fifo.go @@ -83,18 +83,11 @@ func (self *_FIFOCache) Push(row vfilter.Row) { // expire any items which are too old or if we have too many // items. - for { - e := self.rows.Front() - if e == nil { - return - } - - next := e.Next() + for e := self.rows.Front(); e != nil; e = e.Next() { if self.count > self.max_rows { self.rows.Remove(e) self.count -= 1 - e = next continue } @@ -105,16 +98,10 @@ func (self *_FIFOCache) Push(row vfilter.Row) { if time.Now().After(entry.time.Add(self.max_time)) { self.rows.Remove(e) self.count -= 1 - e = next continue } } - - // If we get here the oldest item is still valid so we - // are done. - return } - } func NewFIFOCache( diff --git a/vql/filesystem/raw_registry.go b/vql/filesystem/raw_registry.go index f9102292023..f9d9f388493 100644 --- a/vql/filesystem/raw_registry.go +++ b/vql/filesystem/raw_registry.go @@ -132,7 +132,7 @@ func (self RawRegKeyInfo) MarshalJSON() ([]byte, error) { return result, err } -func (u *RawRegKeyInfo) UnmarshalJSON(data []byte) error { +func (self *RawRegKeyInfo) UnmarshalJSON(data []byte) error { return nil } @@ -283,18 +283,17 @@ func (self *RawRegFileSystemAccessor) New( // When the context is done, close all the files. go func() { - select { - case <-ctx.Done(): - result.mu.Lock() - defer result.mu.Unlock() + <-ctx.Done() - for _, v := range result.fd_cache { - v.fd.Close() - } + result.mu.Lock() + defer result.mu.Unlock() - result.fd_cache = make( - map[string]*RawRegistryFileCache) + for _, v := range result.fd_cache { + v.fd.Close() } + + result.fd_cache = make( + map[string]*RawRegistryFileCache) }() return result diff --git a/vql/filesystem/zip.go b/vql/filesystem/zip.go index 15f50f4198c..79f200d608b 100644 --- a/vql/filesystem/zip.go +++ b/vql/filesystem/zip.go @@ -417,16 +417,15 @@ func (self ZipFileSystemAccessor) New(ctx context.Context) glob.FileSystemAccess // When the context is done, close all the files. go func() { - select { - case <-ctx.Done(): - result.mu.Lock() - defer result.mu.Unlock() + <-ctx.Done() - for _, v := range result.fd_cache { - v.fd.Close() - } - result.fd_cache = make(map[string]*ZipFileCache) + result.mu.Lock() + defer result.mu.Unlock() + + for _, v := range result.fd_cache { + v.fd.Close() } + result.fd_cache = make(map[string]*ZipFileCache) }() return result @@ -445,9 +444,9 @@ func (self *SeekableZip) Seek(offset int64, whence int) (int64, error) { } } - return 0, errors.New(fmt.Sprintf( + return 0, fmt.Errorf( "Seeking to %v (%v) not supported on compressed files.", - offset, whence)) + offset, whence) } func (self *SeekableZip) Stat() (os.FileInfo, error) { diff --git a/vql/networking/uploader.go b/vql/networking/uploader.go index 5e1512a4998..eac3032169f 100644 --- a/vql/networking/uploader.go +++ b/vql/networking/uploader.go @@ -63,14 +63,13 @@ type FileBasedUploader struct { // Turn the path which may have a device name into something which can // be created as a directory. -var sanitize_re = regexp.MustCompile(`[^a-zA-Z0-9_@\(\)\. \-=\{\}\[\]]`) +var sanitize_re = regexp.MustCompile( + `\\\\[\\.\\?]\\([{}a-zA-Z0-9]+).*?\\`) func (self *FileBasedUploader) sanitize_path(path string) string { // Strip any leading devices, and make sure the device name // consists of valid chars. - path = regexp.MustCompile( - `\\\\[\\.\\?]\\([{}a-zA-Z0-9]+).*?\\`). - ReplaceAllString(path, `$1\`) + path = sanitize_re.ReplaceAllString(path, `$1\`) // Split the path into components and escape any non valid // chars. diff --git a/vql/parsers/ntfs.go b/vql/parsers/ntfs.go index 08bac1b0a24..77f8de80e5c 100644 --- a/vql/parsers/ntfs.go +++ b/vql/parsers/ntfs.go @@ -33,11 +33,11 @@ import ( var ( // For convenience we transform paths like c:\Windows -> \\.\c:\Windows driveRegex = regexp.MustCompile( - "(?i)^[/\\\\]?([a-z]:)(.*)") + `(?i)^[/\\]?([a-z]:)(.*)`) deviceDriveRegex = regexp.MustCompile( - "(?i)^(\\\\\\\\[\\?\\.]\\\\[a-zA-Z]:)(.*)") + `(?i)^(\\\\[\?\.]\\[a-zA-Z]:)(.*)`) deviceDirectoryRegex = regexp.MustCompile( - "(?i)^(\\\\\\\\[\\?\\.]\\\\GLOBALROOT\\\\Device\\\\[^/\\\\]+)([/\\\\]?.*)") + `(?i)^(\\\\[\?\.]\\GLOBALROOT\\Device\\[^/\\]+)([/\\]?.*)`) ) func GetDeviceAndSubpath(path string) (device string, subpath string, err error) { diff --git a/vql/parsers/ole.go b/vql/parsers/ole.go index 4fd01288e51..3e783b496ad 100644 --- a/vql/parsers/ole.go +++ b/vql/parsers/ole.go @@ -23,7 +23,6 @@ import ( "errors" "io" "io/ioutil" - "os" "www.velocidex.com/golang/oleparse" "www.velocidex.com/golang/velociraptor/constants" @@ -74,7 +73,7 @@ func _OLEVBAPlugin_ParseFile( } if string(signature) == oleparse.OLE_SIGNATURE { - fd.Seek(0, os.SEEK_SET) + fd.Seek(0, io.SeekStart) data, err := ioutil.ReadAll(io.LimitReader(fd, constants.MAX_MEMORY)) if err != nil { return nil, err