From 79293d8292dba1bee230dd9ddba3dfbab1f0fd80 Mon Sep 17 00:00:00 2001 From: Sahil Silare Date: Tue, 15 Oct 2024 20:51:51 +0530 Subject: [PATCH 1/4] feat: added check for valid git commit and warning message --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index 0dbf1f8d11e8..e6681c17e7f6 100644 --- a/main.go +++ b/main.go @@ -312,6 +312,18 @@ func main() { } } +func isValidCommit(commit string) bool { + if len(commit) != 40 { + return false + } + for _, char := range commit { + if !((char >= '0' && char <= '9') || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F')) { + return false + } + } + return true +} + func run(state overseer.State) { ctx, cancel := context.WithCancelCause(context.Background()) @@ -352,6 +364,9 @@ func run(state overseer.State) { // When setting a base commit, chunks must be scanned in order. if *gitScanSinceCommit != "" { *concurrency = 1 + if !isValidCommit(*gitScanSinceCommit) { + logger.Info("Warning: The provided commit hash appears to be invalid.") + } } if *profile { From b93ae75ab8bcd0f43f6c1e9fcc9e0b7bd9122dd6 Mon Sep 17 00:00:00 2001 From: Sahil Silare Date: Tue, 15 Oct 2024 21:16:37 +0530 Subject: [PATCH 2/4] fix: added a check for short sha --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index e6681c17e7f6..851b2e3219ab 100644 --- a/main.go +++ b/main.go @@ -313,7 +313,7 @@ func main() { } func isValidCommit(commit string) bool { - if len(commit) != 40 { + if len(commit) < 4 { return false } for _, char := range commit { From 27497ab59173e36831cc932389e3feac68e4f18c Mon Sep 17 00:00:00 2001 From: Sahil Silare Date: Tue, 15 Oct 2024 21:18:18 +0530 Subject: [PATCH 3/4] fix: added a function to check short sha --- main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 851b2e3219ab..9ac8352db1dc 100644 --- a/main.go +++ b/main.go @@ -312,16 +312,14 @@ func main() { } } +// Function to check if the commit is valid func isValidCommit(commit string) bool { - if len(commit) < 4 { - return false - } - for _, char := range commit { - if !((char >= '0' && char <= '9') || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F')) { - return false - } - } - return true + for _, char := range commit { + if !((char >= '0' && char <= '9') || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F')) { + return false + } + } + return true } func run(state overseer.State) { From fddb16823507c263086a8e61bab8477b48816ddf Mon Sep 17 00:00:00 2001 From: Sahil Silare Date: Wed, 16 Oct 2024 00:17:43 +0530 Subject: [PATCH 4/4] fix: fixed the git commit hash check to use git cli --- main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 9ac8352db1dc..7fd0dc6c8a57 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "net/http" _ "net/http/pprof" "os" + "os/exec" "os/signal" "runtime" "strconv" @@ -314,12 +315,13 @@ func main() { // Function to check if the commit is valid func isValidCommit(commit string) bool { - for _, char := range commit { - if !((char >= '0' && char <= '9') || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F')) { - return false - } - } - return true + cmd := exec.Command("git", "cat-file", "-t", commit) + output, err := cmd.Output() + if err != nil { + return false + } + + return strings.TrimSpace(string(output)) == "commit" } func run(state overseer.State) {