Skip to content

Commit c882498

Browse files
Merge pull request #6463 from oasisprotocol/martin/fix/sgx-constraints-validation
go/common/node: Fix possible nil dereference
2 parents e47a45f + 47ac06b commit c882498

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.changelog/6463.trivial.md

Whitespace-only changes.

go/common/node/sgx.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,18 @@ func (sc *SGXConstraints) ValidateBasic(cfg *TEEFeatures, isFeatureVersion242 bo
111111
return fmt.Errorf("unsupported SGX constraints version: %d", sc.V)
112112
}
113113

114+
if sc.Policy == nil {
115+
return nil
116+
}
117+
114118
// Check for TDX enablement.
115119
if !cfg.SGX.TDX && sc.Policy.PCS != nil && sc.Policy.PCS.TDX != nil {
116120
return fmt.Errorf("TDX policy not supported")
117121
}
118122

119123
// Check that policy is compliant with the current feature version.
120-
if sc.Policy != nil {
121-
if err := sc.Policy.Validate(isFeatureVersion242); err != nil {
122-
return fmt.Errorf("invalid policy: %w", err)
123-
}
124+
if err := sc.Policy.Validate(isFeatureVersion242); err != nil {
125+
return fmt.Errorf("invalid policy: %w", err)
124126
}
125127

126128
return nil

go/common/node/sgx_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ func TestSGXConstraintsV1(t *testing.T) {
6868
require.NoError(err, "ValidateBasic V1 SGX constraints")
6969
}
7070

71+
func TestSGXConstraintsV1NilPolicy(t *testing.T) {
72+
require := require.New(t)
73+
74+
sc := SGXConstraints{
75+
Versioned: cbor.NewVersioned(1),
76+
}
77+
err := sc.ValidateBasic(&TEEFeatures{SGX: TEEFeaturesSGX{PCS: true}}, true)
78+
require.NoError(err, "ValidateBasic V1 SGX constraints with nil policy")
79+
}
80+
7181
func TestSGXAttestationV0(t *testing.T) {
7282
require := require.New(t)
7383

0 commit comments

Comments
 (0)