From 73b39b5c0d48618b51834468cc520af4490caaea Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sat, 17 Aug 2019 09:35:36 +0000 Subject: [PATCH] Refactor --- config/config.go | 8 ++++++++ kernel.go | 6 +++--- main.go | 4 ++-- pew.go | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 5ab5cb2..25eccd6 100644 --- a/config/config.go +++ b/config/config.go @@ -32,7 +32,9 @@ func (km KernelMask) DockerName() string { type ArtifactType int const ( + // KernelModule is any kind of kernel module KernelModule ArtifactType = iota + // KernelExploit is the privelege escalation exploit KernelExploit ) @@ -111,11 +113,15 @@ func (ka Artifact) Supported(ki KernelInfo) (supported bool, err error) { type DistroType int const ( + // Ubuntu https://ubuntu.com/ Ubuntu DistroType = iota + // CentOS https://www.centos.org/ CentOS + // Debian https://www.debian.org/ Debian ) +// DistroTypeStrings is the string version of enum DistroType var DistroTypeStrings = [...]string{"Ubuntu", "CentOS", "Debian"} // NewDistroType is create new Distro object @@ -160,12 +166,14 @@ func (dt DistroType) MarshalTOML() (data []byte, err error) { return } +// ByRootFS is sorting by .RootFS lexicographically type ByRootFS []KernelInfo func (a ByRootFS) Len() int { return len(a) } func (a ByRootFS) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByRootFS) Less(i, j int) bool { return a[i].RootFS < a[j].RootFS } +// KernelInfo defines kernels.toml entries type KernelInfo struct { DistroType DistroType DistroRelease string // 18.04/7.4.1708/9.1 diff --git a/kernel.go b/kernel.go index b057b30..d7492ee 100644 --- a/kernel.go +++ b/kernel.go @@ -24,7 +24,7 @@ import ( "code.dumpstack.io/tools/out-of-tree/config" ) -const KERNELS_ALL int64 = math.MaxInt64 +const kernelsAll int64 = math.MaxInt64 func kernelListHandler(kcfg config.KernelConfig) (err error) { if len(kcfg.Kernels) == 0 { @@ -496,7 +496,7 @@ func generateKernels(km config.KernelMask, max int64) (err error) { err = dockerImageAppend(km, pkg) if err == nil { - max -= 1 + max-- } else { log.Println("dockerImageAppend", err) } @@ -590,7 +590,7 @@ func kernelGenallHandler(distro, version string, host bool) (err error) { DistroRelease: version, ReleaseMask: ".*", } - err = generateKernels(km, KERNELS_ALL) + err = generateKernels(km, kernelsAll) if err != nil { return } diff --git a/main.go b/main.go index c799b7a..6a0aa92 100644 --- a/main.go +++ b/main.go @@ -118,7 +118,7 @@ func main() { pewCommand := app.Command("pew", "Build, run and test module/exploit") pewMax := pewCommand.Flag("max", "Test no more than X kernels"). - PlaceHolder("X").Default(fmt.Sprint(KERNELS_ALL)).Int64() + PlaceHolder("X").Default(fmt.Sprint(kernelsAll)).Int64() pewRuns := pewCommand.Flag("runs", "Runs per each kernel"). Default("1").Int64() @@ -153,7 +153,7 @@ func main() { "Download random kernels from set defined by regex in "+ "release_mask, but no more than X for each of "+ "release_mask").PlaceHolder("X").Default( - fmt.Sprint(KERNELS_ALL)).Int64() + fmt.Sprint(kernelsAll)).Int64() kernelDockerRegenCommand := kernelCommand.Command("docker-regen", "Regenerate kernels config from out_of_tree_* docker images") kernelGenallCommand := kernelCommand.Command("genall", diff --git a/pew.go b/pew.go index 46c3a82..b180d94 100644 --- a/pew.go +++ b/pew.go @@ -392,7 +392,7 @@ func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath, if supported { found = true - max -= 1 + max-- for i := int64(0); i < runs; i++ { swg.Add() go whatever(&swg, ka, kernel, binaryPath,