Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] - Fix the starting index value for plus line check. #734

Merged
merged 9 commits into from
Aug 25, 2022

Conversation

ahrav
Copy link
Collaborator

@ahrav ahrav commented Aug 24, 2022

Screen Shot 2022-08-24 at 08 16 51 AM

@ahrav ahrav requested a review from a team as a code owner August 24, 2022 15:27
@bill-rich
Copy link
Collaborator

Which repo are you running against to get this crash?

I think a better place to fix this would be to check the slice length at:

if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {

Starting at :3 will include the b/ in the path which we want to exclude

@bill-rich
Copy link
Collaborator

Nevermind on the repo question. I see it in the output.

@ahrav
Copy link
Collaborator Author

ahrav commented Aug 24, 2022

Which repo are you running against to get this crash?

I think a better place to fix this would be to check the slice length at:

if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {

Starting at :3 will include the b/ in the path which we want to exclude

I ran it against the udacity org. I've been using that org for my testing lately. Oh I see you would want it to be :4 since we want to exclude +++. Makes sense. Was the original 6 just a typo here?

Oh nvm we do want it to be 6 but you are suggesting checking that len first.

@bill-rich
Copy link
Collaborator

Which repo are you running against to get this crash?
I think a better place to fix this would be to check the slice length at:

if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {

Starting at :3 will include the b/ in the path which we want to exclude

I ran it against the udacity org. I've been using that org for my testing lately. Oh I see you would want it to be :4 since we want to exclude +++. Makes sense. Was the original 6 just a typo here?

Oh nvm we do want it to be 6 but you are suggesting checking that len first.

I'm curious what line is getting caught that is too short, but the line length check should be 6. That just got overlooked and no cases came up to break it.

I was thinking something like this:

diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.go
index 67388075..925da99c 100644
--- a/pkg/gitparse/gitparse.go
+++ b/pkg/gitparse/gitparse.go
@@ -120,7 +120,7 @@ func RepoPath(source string, head string) (chan Commit, error) {
                        case isIndexLine(line):
                                // NoOp
                        case isPlusFileLine(line):
-                               currentDiff.PathB = strings.TrimRight(string(line[3:]), "\n")
+                               currentDiff.PathB = strings.TrimRight(string(line[6:]), "\n")
                        case isMinusFileLine(line):
                                // NoOp
                        case isPlusDiffLine(line):
@@ -218,7 +218,7 @@ func isModeLine(line []byte) bool {
 
 // --- a/internal/addrs/move_endpoint_module.go
 func isMinusFileLine(line []byte) bool {
-       if len(line) > 3 && bytes.Equal(line[:3], []byte("---")) {
+       if len(line) >= 6 && bytes.Equal(line[:3], []byte("---")) {
                return true
        }
        return false
@@ -226,7 +226,7 @@ func isMinusFileLine(line []byte) bool {
 
 // +++ b/internal/addrs/move_endpoint_module.go
 func isPlusFileLine(line []byte) bool {
-       if len(line) > 3 && bytes.Equal(line[:3], []byte("+++")) {
+       if len(line) >= 6 && bytes.Equal(line[:3], []byte("+++")) {
                return true
        }
        return false

@mcastorina
Copy link
Collaborator

mcastorina commented Aug 24, 2022

Tangent, but the bytes package has almost all the same functions as strings, including bytes.TrimRight and bytes.HasPrefix.

That should be more performant and convenient than converting to strings or checking slice lengths and comparing.

(Something I learned recently but not necessarily applicable here).

@ahrav ahrav requested a review from a team August 24, 2022 21:11
@mcastorina
Copy link
Collaborator

I know it's a small change, but would it be possible to add a test to prevent future regressions?

Maybe in a follow-up PR if this is urgent.

Copy link
Collaborator

@bill-rich bill-rich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I like the additional tests.

@ahrav ahrav merged commit 20cdcbc into main Aug 25, 2022
@ahrav ahrav deleted the bug-plus-line-out-of-range branch August 25, 2022 17:45
javajawa added a commit to mewbotorg/mewbot that referenced this pull request Sep 2, 2022
Add Honeycomb detector by @​MNThomson in trufflesecurity/trufflehog#687
Feature/scalr detector by @​lonmarsDev in trufflesecurity/trufflehog#519
added websitepulse detector by @​lonmarsDev in trufflesecurity/trufflehog#516
added tokeet detector by @​lonmarsDev in trufflesecurity/trufflehog#515
Feature/salesmate detector by @​lonmarsDev in trufflesecurity/trufflehog#514
added kanbantool detector by @​lonmarsDev in trufflesecurity/trufflehog#513
added demio detector by @​lonmarsDev in trufflesecurity/trufflehog#512
added heatmapapi detector by @​lonmarsDev in trufflesecurity/trufflehog#509
added getresponse detector by @​lonmarsDev in trufflesecurity/trufflehog#506
added codeclimate detector by @​lonmarsDev in trufflesecurity/trufflehog#484
added flightlabs detector by @​ladybug0125 in trufflesecurity/trufflehog#475
added prodpad detector by @​lonmarsDev in trufflesecurity/trufflehog#470
added lemlist detector by @​lonmarsDev in trufflesecurity/trufflehog#469
added formsite detector by @​lonmarsDev in trufflesecurity/trufflehog#467
added docparser detector by @​lonmarsDev in trufflesecurity/trufflehog#458
added parseur detector by @​lonmarsDev in trufflesecurity/trufflehog#454
Added ecostruxureit detector by @​roxanne-tampus in trufflesecurity/trufflehog#555
Added transferwise detector by @​roxanne-tampus in trufflesecurity/trufflehog#558
Added holistic detector by @​roxanne-tampus in trufflesecurity/trufflehog#556
Added twist detector by @​roxanne-tampus in trufflesecurity/trufflehog#549
Added monkeylearn detector by @​roxanne-tampus in trufflesecurity/trufflehog#553
Added gtmetrix detector by @​roxanne-tampus in trufflesecurity/trufflehog#554
Added duply detector by @​roxanne-tampus in trufflesecurity/trufflehog#552
Added braintreepayments detector by @​roxanne-tampus in trufflesecurity/trufflehog#541
added apilayer scanner by @​lonmarsDev in trufflesecurity/trufflehog#368
added appointed scanner by @​lonmarsDev in trufflesecurity/trufflehog#425
[bug] - Fix the starting index value for plus line check. by @​ahrav in trufflesecurity/trufflehog#734
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants