Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
af02e979
Unverified
Commit
af02e979
authored
May 23, 2022
by
Martin Holst Swende
Committed by
GitHub
May 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: validate fieldnames, fixes #24930 (#24932)
parent
59ac229f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
base_test.go
accounts/abi/bind/base_test.go
+8
-0
type.go
accounts/abi/type.go
+32
-0
No files found.
accounts/abi/bind/base_test.go
View file @
af02e979
...
...
@@ -488,3 +488,11 @@ func TestCall(t *testing.T) {
}
}
}
// TestCrashers contains some strings which previously caused the abi codec to crash.
func
TestCrashers
(
t
*
testing
.
T
)
{
abi
.
JSON
(
strings
.
NewReader
(
`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"_1"}]}]}]`
))
abi
.
JSON
(
strings
.
NewReader
(
`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"&"}]}]}]`
))
abi
.
JSON
(
strings
.
NewReader
(
`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"----"}]}]}]`
))
abi
.
JSON
(
strings
.
NewReader
(
`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"foo.Bar"}]}]}]`
))
}
accounts/abi/type.go
View file @
af02e979
...
...
@@ -23,6 +23,8 @@ import (
"regexp"
"strconv"
"strings"
"unicode"
"unicode/utf8"
"github.com/ethereum/go-ethereum/common"
)
...
...
@@ -173,6 +175,9 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
if
err
!=
nil
{
return
Type
{},
err
}
if
!
isValidFieldName
(
fieldName
)
{
return
Type
{},
fmt
.
Errorf
(
"field %d has invalid name"
,
idx
)
}
overloadedNames
[
fieldName
]
=
fieldName
fields
=
append
(
fields
,
reflect
.
StructField
{
Name
:
fieldName
,
// reflect.StructOf will panic for any exported field.
...
...
@@ -399,3 +404,30 @@ func getTypeSize(t Type) int {
}
return
32
}
// isLetter reports whether a given 'rune' is classified as a Letter.
// This method is copied from reflect/type.go
func
isLetter
(
ch
rune
)
bool
{
return
'a'
<=
ch
&&
ch
<=
'z'
||
'A'
<=
ch
&&
ch
<=
'Z'
||
ch
==
'_'
||
ch
>=
utf8
.
RuneSelf
&&
unicode
.
IsLetter
(
ch
)
}
// isValidFieldName checks if a string is a valid (struct) field name or not.
//
// According to the language spec, a field name should be an identifier.
//
// identifier = letter { letter | unicode_digit } .
// letter = unicode_letter | "_" .
// This method is copied from reflect/type.go
func
isValidFieldName
(
fieldName
string
)
bool
{
for
i
,
c
:=
range
fieldName
{
if
i
==
0
&&
!
isLetter
(
c
)
{
return
false
}
if
!
(
isLetter
(
c
)
||
unicode
.
IsDigit
(
c
))
{
return
false
}
}
return
len
(
fieldName
)
>
0
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment