Skip to content

binding maybe infinite recurse #3791

@FGYFFFF

Description

@FGYFFFF
  • With issues:
    • Use the search tool before opening a new issue.
    • Please provide source code and commit sha if you found a bug.
    • Review existing issues and provide feedback or react to them.

Description

when there is no value for the 'Parent' field, the mapping maybe infinite recurse.

// form_mapping_test.go
func TestInfiniteRecursion(t *testing.T) {
	type Req struct {
		Parent *Req `form:"parent"`
	}
	var s = Req{}
	err := mappingByPtr(&s, formSource{}, "form")
	assert.NoError(t, err)
}

example:
my struct is below, the 'Foo2' maybe pass by query. But sometimes, I forget to pass 'foo2' in query parameters, the server will over stack

	type Req struct {
		Foo  string `form:"foo"`
		Bar  string `form:"bar"`
		Foo1 string `form:"Foo"`
		Bar1 string `form:"Bar"`
		Foo2 *Req   `form:"foo2"`
	}

How to reproduce

// form_mapping_test.go
func TestInfiniteRecursion(t *testing.T) {
	type Req struct {
		Parent *Req `form:"parent"`
	}
	var s = Req{}
	err := mappingByPtr(&s, formSource{}, "form")
	assert.NoError(t, err)
}

Expectations

binding successfully or error, but not stack overflow

Actual result

image

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions