Skip to content

Fix nil pointer panic on invalid terminal total difficulty - #83

Open
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/spec-ttd-nil-deref
Open

Fix nil pointer panic on invalid terminal total difficulty#83
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/spec-ttd-nil-deref

Conversation

@damilolaedwards

Copy link
Copy Markdown

Summary

state.NewSpec discarded the ok flag from big.Int.SetString and dereferenced the result unconditionally. SetString returns nil on any parse failure, so a spec response with a non-decimal TERMINAL_TOTAL_DIFFICULTY value (for example a hex-encoded one) crashes the caller with a nil pointer dereference.

Fix leaves the field at its zero value when parsing fails instead of dereferencing a nil result.

Test plan

  • Added table-driven tests in pkg/beacon/state/spec_test.go covering decimal, zero, hex-encoded bytes, non-numeric string, empty string, and absent field
  • Confirmed the new tests fail against the old code and pass against the fix
  • go build ./..., go vet ./..., go test -race ./... all green

SetString returns a nil result on parse failure, and the return value was
being discarded before dereferencing it. A spec response with a
non-decimal TERMINAL_TOTAL_DIFFICULTY value would crash the caller.
Now it just leaves the field at its zero value when parsing fails.
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.

1 participant