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

services/git:bugfix - error git diff breaking parse and invalid filepath #838

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

nathanmartinszup
Copy link
Contributor

@nathanmartinszup nathanmartinszup commented Dec 2, 2021

Signed-off-by: Nathan Martins nathan.martins@zup.com.br

- What I did

  • Changing function that removes default src/ horusec folder from filepath to prevent it being reported as /hcl/example1/main.tf, which will be looked up from root and break git blame function. Now it will return the correted path
    like this hcl/example1/main.tf

  • Added flag --no-patch into git blame function to avoid diff info. Without it, in some cases will return extra information and break the json parse. Following the example of the output that results in error.

                {
			"author": "Otávio Santana",
			"email":"otaviopolianasantana@gmail.com",
			"message": "Updates sample to Java Vulnerabilities (#4)",
			"date": "2021-12-02 08:22:25 -0300",
			"commitHash": "3aea61743d526c833f0a3ddf289807dafa505370"
		}

diff --git a/java/example1/src/main/java/br/com/zup/vulnerabilities/trust/AllTrustSSLSocketFactoryIssue.java b/java/example1/src/main/java/br/com/zup/vulnerabilities/trust/AllTrustSSLSocketFactoryIssue.java
--- /dev/null
+++ b/java/example1/src/main/java/br/com/zup/vulnerabilities/trust/AllTrustSSLSocketFactoryIssue.java
@@ -0,0 +39,1 @@
+        }

- How to verify it

- Description for the changelog

@nathanmartinszup nathanmartinszup force-pushed the bugfix/commit-author branch 3 times, most recently from 259fe2b to 311c7ca Compare December 3, 2021 11:47
@nathanmartinszup nathanmartinszup marked this pull request as ready for review December 3, 2021 11:55
Copy link
Contributor

@matheusalcantarazup matheusalcantarazup left a comment

Choose a reason for hiding this comment

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

Can we add a new test case on git to assert that this bug will not occur again?

@nathanmartinszup
Copy link
Contributor Author

Can we add a new test case on git to assert that this bug will not occur again?

Done!

Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
Comment on lines -147 to -154
func (g *Git) getCleanOutput(output []byte) []byte {
// Output from git log contains the diff changes
// so we need to extract only the json output data.
if idx := bytes.LastIndex(output, []byte("}")); idx >= 0 {
return bytes.ReplaceAll(output[:idx+1], []byte("^^^^^"), []byte(`"`))
}
logger.LogWarn(fmt.Sprintf("Could not to clean git blame output: %s", output))
return []byte("")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took a closer look at the code and saw this function with some unnecessary stuff. Changed to just relace the carets.

@nathanmartinszup nathanmartinszup merged commit f613714 into main Dec 3, 2021
@nathanmartinszup nathanmartinszup deleted the bugfix/commit-author branch December 3, 2021 16:22
nathanmartinszup added a commit that referenced this pull request Dec 3, 2021
…ath (#838)

Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
nathanmartinszup added a commit that referenced this pull request Dec 3, 2021
…ath (#838)

Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
(cherry picked from commit f613714)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants