Skip to content

check struct field name is a string in Fetch and get#973

Open
netliomax25-code wants to merge 1 commit into
expr-lang:masterfrom
netliomax25-code:struct-key-string-check
Open

check struct field name is a string in Fetch and get#973
netliomax25-code wants to merge 1 commit into
expr-lang:masterfrom
netliomax25-code:struct-key-string-check

Conversation

@netliomax25-code

Copy link
Copy Markdown

runtime.Fetch (runtime.go:76) and the get builtin (lib.go:598) read a struct field name with an unchecked i.(string), so indexing a struct held in an any value with a non-string key panics with a raw interface conversion. Use a checked assertion so Fetch falls through to its usual "cannot fetch" error and get returns nil per its no-panic contract.

@netliomax25-code

Copy link
Copy Markdown
Author

any update?

@sanmaxdev sanmaxdev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The struct-key guard is consistent across get and runtime field access, and both paths have regression coverage.

Passed:

  • go test ./...
  • git diff origin/master...HEAD --check

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.

2 participants