Skip to content

Commit

Permalink
Various changes for fixing static analysis comments. (Velocidex#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette authored Sep 17, 2019
1 parent cf7addf commit f78fe7d
Show file tree
Hide file tree
Showing 30 changed files with 79 additions and 123 deletions.
2 changes: 0 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 0 additions & 13 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
2 changes: 0 additions & 2 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
type statusRecorder struct {
http.ResponseWriter
http.Flusher
http.CloseNotifier
status int
error []byte
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions artifacts/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
package artifacts

import (
"flag"
"testing"

"github.com/stretchr/testify/assert"
actions_proto "www.velocidex.com/golang/velociraptor/actions/proto"
)

var (
environment = flag.String("test.env", "",
"The name of the test environment.")

// Artifacts 1 and 2 are invalid: cyclic
artifact1 = `
name: Artifact1
Expand Down
4 changes: 2 additions & 2 deletions artifacts/assets/ab0x.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion artifacts/obfuscation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions bin/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 4 additions & 8 deletions bin/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)")

Expand Down
1 change: 0 additions & 1 deletion crypto/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
type Obfuscator struct {
mu sync.Mutex
key []byte
iv []byte
crypter cipher.Block
}

Expand Down
5 changes: 2 additions & 3 deletions file_store/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package file_store

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions file_store/csv/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (
var (
number_regex = regexp.MustCompile(
`^(?P<Number>[-+]?\d*\.?\d+([eE][-+]?\d+)?)$`)
integer_regex = regexp.MustCompile(
"^[+-]?[0-9]+$")

protected_prefix = regexp.MustCompile(
`^( |\{|\[|true|false|base64:)`)
)
Expand Down
6 changes: 3 additions & 3 deletions file_store/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions flows/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (self *ArtifactCollector) ProcessMessage(
hunt.Stats.TotalClientsWithResults++
return nil
})
if err != nil {
return err
}
}

return flow_obj.Complete(config_obj)
Expand Down
2 changes: 1 addition & 1 deletion flows/proto/flows.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flows/proto/flows.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}];
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
14 changes: 5 additions & 9 deletions reporting/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"sync"
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions reporting/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func FormatDescription(
return description
}

return string(buffer.Bytes())
return buffer.String()
}

func (self *Expansions) DocFrom(artifact string) string {
Expand Down Expand Up @@ -132,5 +132,5 @@ func (self *Expansions) Query(queries ...string) string {
table.Render()
}

return string(result.Bytes())
return result.String()
}
Loading

0 comments on commit f78fe7d

Please sign in to comment.