Skip to content

Commit

Permalink
Fix vuln. source name dereference if source nil (#110)
Browse files Browse the repository at this point in the history
* Fix vuln. source name dereference if source nil

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

* Fix complaints using printf from go vet

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

* Fix complaints using printf from go vet

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

* Adjust golangci-lint checks for govet

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

* Update golangci-lint action

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

* Fix golangci-lint errors in test file due to Errorf() without format string

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

* Fix golangci-lint errors in test file due to Errorf() without format string

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>

---------

Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>
  • Loading branch information
mrutkows authored Nov 7, 2024
1 parent b538cf9 commit df2e6c4
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
go-version: '1.21'
#cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v5
uses: golangci/golangci-lint-action@v6
with:
# Optional: golangci-lint command line arguments.
args: -D errcheck
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ run:
# https://golangci-lint.run/usage/false-positives/
# https://staticcheck.io/docs/
linters-settings:
govet:
disable:
- printf
staticcheck:
checks:
- all
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"gojsondiff",
"gojsonschema",
"gomod",
"govet",
"GTPL",
"hasher",
"hashstructure",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ In this example, the `--from` filter will return the entire JSON components arra
]
```

**Note**: The command for this example only used the `--from` flag and did not need to supply `--select '*'` as this us the default.
**Note**: The command for this example only used the `--from` flag and did not need to supply `--select '*'` as this is the default.

##### Example: Filter result entries with a specified value

Expand Down
5 changes: 3 additions & 2 deletions cmd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package cmd

import (
"encoding/csv"
"errors"
"fmt"
"io"
"sort"
Expand Down Expand Up @@ -395,7 +396,7 @@ func DisplayComponentListCSV(bom *schema.BOM, writer io.Writer, flags utils.Comp
// unable to emit an error message into output stream
return getLogger().Errorf("error writing to output (%v): %s", currentRow, err)
}
return fmt.Errorf(currentRow[0])
return errors.New(MSG_OUTPUT_NO_RESOURCES_FOUND)
}

// Sort Components prior to outputting
Expand Down Expand Up @@ -443,7 +444,7 @@ func DisplayComponentListMarkdown(bom *schema.BOM, writer io.Writer, flags utils
// Emit no components found warning into output
if len(entries) == 0 {
fmt.Fprintf(writer, "%s\n", MSG_OUTPUT_NO_COMPONENTS_FOUND)
return fmt.Errorf(MSG_OUTPUT_NO_COMPONENTS_FOUND)
return errors.New(MSG_OUTPUT_NO_COMPONENTS_FOUND)
}

// Sort Components prior to outputting
Expand Down
7 changes: 4 additions & 3 deletions cmd/license_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package cmd

import (
"encoding/csv"
"errors"
"fmt"
"io"
"sort"
Expand Down Expand Up @@ -262,7 +263,7 @@ func DisplayLicensePoliciesTabbedText(writer io.Writer, filteredPolicyMap *slice
// Emit no schemas found warning into output
// TODO Use only for Warning messages, do not emit in output table
if len(keyNames) == 0 {
return fmt.Errorf(MSG_OUTPUT_NO_POLICIES_FOUND)
return errors.New(MSG_OUTPUT_NO_POLICIES_FOUND)
}

// Sort entries by family name
Expand Down Expand Up @@ -353,7 +354,7 @@ func DisplayLicensePoliciesCSV(writer io.Writer, filteredPolicyMap *slicemultima
// TODO Use only for Warning messages, do not emit in output table
if len(keyNames) == 0 {
fmt.Fprintf(writer, "%s\n", MSG_OUTPUT_NO_POLICIES_FOUND)
return fmt.Errorf(MSG_OUTPUT_NO_POLICIES_FOUND)
return errors.New(MSG_OUTPUT_NO_POLICIES_FOUND)
}

// Sort entries by family name
Expand Down Expand Up @@ -405,7 +406,7 @@ func DisplayLicensePoliciesMarkdown(writer io.Writer, filteredPolicyMap *slicemu
// TODO Use only for Warning messages, do not emit in output table
if len(keyNames) == 0 {
fmt.Fprintf(writer, "%s\n", MSG_OUTPUT_NO_POLICIES_FOUND)
return fmt.Errorf(MSG_OUTPUT_NO_POLICIES_FOUND)
return errors.New(MSG_OUTPUT_NO_POLICIES_FOUND)
}

// Sort entries by family name
Expand Down
42 changes: 21 additions & 21 deletions cmd/license_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ func TestLicensePolicyUsageConjunctionsANDCombinations(t *testing.T) {
// Set the policy file to the reduced, 3-entry policy file used to test the 3 policy states
testPolicyConfig, err := LoadCustomPolicyFile(POLICY_FILE_GOOD_BAD_MAYBE)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

// 1. schema.POLICY_DENY AND schema.POLICY_ALLOW
EXP := "Bad AND Good"
EXPECTED_USAGE_POLICY := schema.POLICY_DENY
parsedExpression, err := schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy := parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -165,7 +165,7 @@ func TestLicensePolicyUsageConjunctionsANDCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_DENY
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -177,7 +177,7 @@ func TestLicensePolicyUsageConjunctionsANDCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_DENY
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -189,7 +189,7 @@ func TestLicensePolicyUsageConjunctionsANDCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_NEEDS_REVIEW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -201,7 +201,7 @@ func TestLicensePolicyUsageConjunctionsANDCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_NEEDS_REVIEW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -213,7 +213,7 @@ func TestLicensePolicyUsageConjunctionsANDCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_ALLOW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -235,15 +235,15 @@ func TestLicensePolicyUsageConjunctionsORCombinations(t *testing.T) {
// Set the policy file to the reduced, 3-entry policy file used to test the 3 policy states
testPolicyConfig, err := LoadCustomPolicyFile(POLICY_FILE_GOOD_BAD_MAYBE)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

// 1. schema.POLICY_ALLOW OR schema.POLICY_DENY
EXP := "Good OR Bad"
EXPECTED_USAGE_POLICY := schema.POLICY_ALLOW
parsedExpression, err := schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy := parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -255,7 +255,7 @@ func TestLicensePolicyUsageConjunctionsORCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_ALLOW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -267,7 +267,7 @@ func TestLicensePolicyUsageConjunctionsORCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_ALLOW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -279,7 +279,7 @@ func TestLicensePolicyUsageConjunctionsORCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_NEEDS_REVIEW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -291,7 +291,7 @@ func TestLicensePolicyUsageConjunctionsORCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_NEEDS_REVIEW
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -303,7 +303,7 @@ func TestLicensePolicyUsageConjunctionsORCombinations(t *testing.T) {
EXPECTED_USAGE_POLICY = schema.POLICY_DENY
parsedExpression, err = schema.ParseExpression(testPolicyConfig, EXP)
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
resolvedPolicy = parsedExpression.CompoundUsagePolicy
if resolvedPolicy != EXPECTED_USAGE_POLICY {
Expand All @@ -323,7 +323,7 @@ func TestLicensePolicyFamilyUsagePolicyConflict(t *testing.T) {

// Note: the conflict is only encountered on the "hash"; load only loads what policies are defined in the config.
if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}
}

Expand All @@ -334,7 +334,7 @@ func TestLicensePolicyCustomListGoodBadMaybe(t *testing.T) {
outputBuffer, err := innerTestLicensePolicyList(t, lti)

if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
return
}

Expand Down Expand Up @@ -695,7 +695,7 @@ func TestLicensePolicyMatchByExpFailureInvalidRightExp(t *testing.T) {
expressionTree, err := schema.ParseExpression(LicensePolicyConfig, EXP)

if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

getLogger().Tracef("Parsed expression:\n%v", expressionTree)
Expand All @@ -716,7 +716,7 @@ func TestLicensePolicyMatchByExpFailureInvalidLeftExp(t *testing.T) {
expressionTree, err := schema.ParseExpression(LicensePolicyConfig, EXP)

if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

getLogger().Tracef("Parsed expression:\n%v", expressionTree)
Expand All @@ -737,7 +737,7 @@ func TestLicensePolicyExpressionBSD3OrMIT(t *testing.T) {
expressionTree, err := schema.ParseExpression(LicensePolicyConfig, EXP)

if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

getLogger().Tracef("Parsed expression:\n%v", expressionTree)
Expand All @@ -759,7 +759,7 @@ func TestLicensePolicyExpressionMultipleConjunctions(t *testing.T) {
expressionTree, err := schema.ParseExpression(LicensePolicyConfig, EXP)

if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

getLogger().Tracef("Parsed expression:\n%v", expressionTree)
Expand All @@ -777,7 +777,7 @@ func TestLicensePolicyExpressionMultipleConjunctions(t *testing.T) {
expressionTree, err = schema.ParseExpression(LicensePolicyConfig, EXP)

if err != nil {
t.Errorf(err.Error())
t.Error(err.Error())
}

getLogger().Tracef("Parsed expression:\n%v", expressionTree)
Expand Down
Loading

0 comments on commit df2e6c4

Please sign in to comment.