Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d537a44

Browse files
committed
pr fixes
Signed-off-by: balteravishay <[email protected]>
1 parent f0e54b1 commit d537a44

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

probes/unsafeblock/def.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ implementation: >
2525
- for go the probe will look for the use of the `unsafe` include directive.
2626
- for c# the probe will look at the csproj and identify the use of the `AllowUnsafeBlocks` property.
2727
outcome:
28-
- For supported ecosystem, the probe returns OutcomeFalse per unsafe block.
29-
- If the project has no unsafe blocks, the probe returns OutcomeTrue.
28+
- For supported ecosystem, the probe returns OutcomeTrue per unsafe block.
29+
- If the project has no unsafe blocks, the probe returns OutcomeFalse.
3030
remediation:
31-
onOutcome: False
31+
onOutcome: True
3232
effort: Medium
3333
text:
3434
- Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.

probes/unsafeblock/impl.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ func init() {
5959
}
6060

6161
func Run(raw *checker.CheckRequest) (found []finding.Finding, probeName string, err error) {
62-
prominentLangs, err := getLanguageChecks(raw)
62+
repoLanguageChecks, err := getLanguageChecks(raw)
6363
if err != nil {
6464
return nil, Probe, err
6565
}
6666
findings := []finding.Finding{}
67-
for _, lang := range prominentLangs {
67+
for _, lang := range repoLanguageChecks {
6868
langFindings, err := lang.funcPointer(raw)
6969
if err != nil {
7070
return nil, Probe, fmt.Errorf("error while running function for language %s: %w", lang.Desc, err)
@@ -73,7 +73,7 @@ func Run(raw *checker.CheckRequest) (found []finding.Finding, probeName string,
7373
}
7474
if len(findings) == 0 {
7575
found, err := finding.NewWith(fs, Probe,
76-
"All supported ecosystems do not declare or use unsafe code blocks", nil, finding.OutcomeTrue)
76+
"All supported ecosystems do not declare or use unsafe code blocks", nil, finding.OutcomeFalse)
7777
if err != nil {
7878
return nil, Probe, fmt.Errorf("create finding: %w", err)
7979
}
@@ -87,9 +87,6 @@ func getLanguageChecks(raw *checker.CheckRequest) ([]languageMemoryCheckConfig,
8787
if err != nil {
8888
return nil, fmt.Errorf("cannot get langs of repo: %w", err)
8989
}
90-
if len(langs) == 0 {
91-
return []languageMemoryCheckConfig{}, nil
92-
}
9390
if len(langs) == 1 && langs[0].Name == clients.All {
9491
return getAllLanguages(), nil
9592
}
@@ -150,7 +147,7 @@ func goCodeUsesUnsafePackage(path string, content []byte, args ...interface{}) (
150147
found, err := finding.NewWith(fs, Probe,
151148
"Golang code uses the unsafe package", &finding.Location{
152149
Path: path, LineStart: &lineStart,
153-
}, finding.OutcomeFalse)
150+
}, finding.OutcomeTrue)
154151
if err != nil {
155152
return false, fmt.Errorf("create finding: %w", err)
156153
}
@@ -198,7 +195,7 @@ func csProjAllosUnsafeBlocks(path string, content []byte, args ...interface{}) (
198195
found, err := finding.NewWith(fs, Probe,
199196
"C# project file allows the use of unsafe blocks", &finding.Location{
200197
Path: path,
201-
}, finding.OutcomeFalse)
198+
}, finding.OutcomeTrue)
202199
if err != nil {
203200
return false, fmt.Errorf("create finding: %w", err)
204201
}

probes/unsafeblock/impl_test.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ossf/scorecard/v5/clients"
2929
mockrepo "github.com/ossf/scorecard/v5/clients/mockclients"
3030
"github.com/ossf/scorecard/v5/finding"
31+
scut "github.com/ossf/scorecard/v5/utests"
3132
)
3233

3334
func Test_Run(t *testing.T) {
@@ -49,7 +50,7 @@ func Test_Run(t *testing.T) {
4950
{
5051
Probe: Probe,
5152
Message: "All supported ecosystems do not declare or use unsafe code blocks",
52-
Outcome: finding.OutcomeTrue,
53+
Outcome: finding.OutcomeFalse,
5354
},
5455
},
5556
err: nil,
@@ -65,7 +66,7 @@ func Test_Run(t *testing.T) {
6566
{
6667
Probe: Probe,
6768
Message: "All supported ecosystems do not declare or use unsafe code blocks",
68-
Outcome: finding.OutcomeTrue,
69+
Outcome: finding.OutcomeFalse,
6970
},
7071
},
7172
err: nil,
@@ -81,7 +82,7 @@ func Test_Run(t *testing.T) {
8182
{
8283
Probe: Probe,
8384
Message: "All supported ecosystems do not declare or use unsafe code blocks",
84-
Outcome: finding.OutcomeTrue,
85+
Outcome: finding.OutcomeFalse,
8586
},
8687
},
8788
err: nil,
@@ -98,7 +99,7 @@ func Test_Run(t *testing.T) {
9899
{
99100
Probe: Probe,
100101
Message: "All supported ecosystems do not declare or use unsafe code blocks",
101-
Outcome: finding.OutcomeTrue,
102+
Outcome: finding.OutcomeFalse,
102103
},
103104
},
104105
err: nil,
@@ -115,7 +116,7 @@ func Test_Run(t *testing.T) {
115116
{
116117
Probe: Probe,
117118
Message: "All supported ecosystems do not declare or use unsafe code blocks",
118-
Outcome: finding.OutcomeTrue,
119+
Outcome: finding.OutcomeFalse,
119120
},
120121
},
121122
err: nil,
@@ -132,7 +133,7 @@ func Test_Run(t *testing.T) {
132133
{
133134
Probe: Probe,
134135
Message: "Golang code uses the unsafe package",
135-
Outcome: finding.OutcomeFalse,
136+
Outcome: finding.OutcomeTrue,
136137
Remediation: &finding.Remediation{
137138
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
138139
Effort: 2,
@@ -155,7 +156,7 @@ func Test_Run(t *testing.T) {
155156
{
156157
Probe: Probe,
157158
Message: "Golang code uses the unsafe package",
158-
Outcome: finding.OutcomeFalse,
159+
Outcome: finding.OutcomeTrue,
159160
Remediation: &finding.Remediation{
160161
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
161162
Effort: 2,
@@ -178,7 +179,7 @@ func Test_Run(t *testing.T) {
178179
{
179180
Probe: Probe,
180181
Message: "Golang code uses the unsafe package",
181-
Outcome: finding.OutcomeFalse,
182+
Outcome: finding.OutcomeTrue,
182183
Remediation: &finding.Remediation{
183184
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
184185
Effort: 2,
@@ -199,7 +200,7 @@ func Test_Run(t *testing.T) {
199200
{
200201
Probe: Probe,
201202
Message: "All supported ecosystems do not declare or use unsafe code blocks",
202-
Outcome: finding.OutcomeTrue,
203+
Outcome: finding.OutcomeFalse,
203204
},
204205
},
205206
err: nil,
@@ -216,7 +217,7 @@ func Test_Run(t *testing.T) {
216217
{
217218
Probe: Probe,
218219
Message: "All supported ecosystems do not declare or use unsafe code blocks",
219-
Outcome: finding.OutcomeTrue,
220+
Outcome: finding.OutcomeFalse,
220221
},
221222
},
222223
err: nil,
@@ -233,7 +234,7 @@ func Test_Run(t *testing.T) {
233234
{
234235
Probe: Probe,
235236
Message: "All supported ecosystems do not declare or use unsafe code blocks",
236-
Outcome: finding.OutcomeTrue,
237+
Outcome: finding.OutcomeFalse,
237238
},
238239
},
239240
err: nil,
@@ -250,7 +251,7 @@ func Test_Run(t *testing.T) {
250251
{
251252
Probe: Probe,
252253
Message: "C# project file allows the use of unsafe blocks",
253-
Outcome: finding.OutcomeFalse,
254+
Outcome: finding.OutcomeTrue,
254255
Remediation: &finding.Remediation{
255256
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
256257
Effort: 2,
@@ -273,7 +274,7 @@ func Test_Run(t *testing.T) {
273274
{
274275
Probe: Probe,
275276
Message: "C# project file allows the use of unsafe blocks",
276-
Outcome: finding.OutcomeFalse,
277+
Outcome: finding.OutcomeTrue,
277278
Remediation: &finding.Remediation{
278279
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
279280
Effort: 2,
@@ -296,7 +297,7 @@ func Test_Run(t *testing.T) {
296297
{
297298
Probe: Probe,
298299
Message: "C# project file allows the use of unsafe blocks",
299-
Outcome: finding.OutcomeFalse,
300+
Outcome: finding.OutcomeTrue,
300301
Remediation: &finding.Remediation{
301302
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
302303
Effort: 2,
@@ -318,7 +319,7 @@ func Test_Run(t *testing.T) {
318319
{
319320
Probe: Probe,
320321
Message: "All supported ecosystems do not declare or use unsafe code blocks",
321-
Outcome: finding.OutcomeTrue,
322+
Outcome: finding.OutcomeFalse,
322323
},
323324
},
324325
err: nil,
@@ -336,7 +337,7 @@ func Test_Run(t *testing.T) {
336337
{
337338
Probe: Probe,
338339
Message: "All supported ecosystems do not declare or use unsafe code blocks",
339-
Outcome: finding.OutcomeTrue,
340+
Outcome: finding.OutcomeFalse,
340341
},
341342
},
342343
err: nil,
@@ -354,7 +355,7 @@ func Test_Run(t *testing.T) {
354355
{
355356
Probe: Probe,
356357
Message: "C# project file allows the use of unsafe blocks",
357-
Outcome: finding.OutcomeFalse,
358+
Outcome: finding.OutcomeTrue,
358359
Remediation: &finding.Remediation{
359360
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
360361
Effort: 2,
@@ -377,7 +378,7 @@ func Test_Run(t *testing.T) {
377378
{
378379
Probe: Probe,
379380
Message: "Golang code uses the unsafe package",
380-
Outcome: finding.OutcomeFalse,
381+
Outcome: finding.OutcomeTrue,
381382
Remediation: &finding.Remediation{
382383
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
383384
Effort: 2,
@@ -400,7 +401,7 @@ func Test_Run(t *testing.T) {
400401
{
401402
Probe: Probe,
402403
Message: "Golang code uses the unsafe package",
403-
Outcome: finding.OutcomeFalse,
404+
Outcome: finding.OutcomeTrue,
404405
Remediation: &finding.Remediation{
405406
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
406407
Effort: 2,
@@ -410,7 +411,7 @@ func Test_Run(t *testing.T) {
410411
{
411412
Probe: Probe,
412413
Message: "C# project file allows the use of unsafe blocks",
413-
Outcome: finding.OutcomeFalse,
414+
Outcome: finding.OutcomeTrue,
414415
Remediation: &finding.Remediation{
415416
Text: "Visit the OpenSSF Memory Safety SIG guidance on how to make your project memory safe.\nGuidance for [Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-memory-safe-by-default-languages.md)\nGuidance for [Non Memory-Safe By Default Languages](https://github.com/ossf/Memory-Safety/blob/main/docs/best-practice-non-memory-safe-by-default-languages.md)",
416417
Effort: 2,
@@ -438,7 +439,7 @@ func Test_Run(t *testing.T) {
438439
return os.Open(file)
439440
}).AnyTimes()
440441
raw.RepoClient = mockRepoClient
441-
raw.Dlogger = checker.NewLogger()
442+
raw.Dlogger = &scut.TestDetailLogger{}
442443
findings, _, err := Run(raw)
443444
if err != nil {
444445
t.Fatalf("unexpected error: %v", err)
@@ -460,7 +461,7 @@ func Test_Run_Error_ListProgrammingLanguages(t *testing.T) {
460461
return nil, fmt.Errorf("error")
461462
}).AnyTimes()
462463
raw.RepoClient = mockRepoClient
463-
raw.Dlogger = checker.NewLogger()
464+
raw.Dlogger = &scut.TestDetailLogger{}
464465
_, _, err := Run(raw)
465466
if err == nil {
466467
t.Fatalf("expected error: %v", err)
@@ -500,7 +501,7 @@ func Test_Run_Error_OnMatchingFileContentDo(t *testing.T) {
500501
return nil, fmt.Errorf("error")
501502
}).AnyTimes()
502503
raw.RepoClient = mockRepoClient
503-
raw.Dlogger = checker.NewLogger()
504+
raw.Dlogger = &scut.TestDetailLogger{}
504505
_, _, err := Run(raw)
505506
if err.Error() != tt.expectedErr.Error() {
506507
t.Error(cmp.Diff(err, tt.expectedErr, cmpopts.EquateErrors()))

0 commit comments

Comments
 (0)