diegogub / aranGO

Golang driver for ArangoDB
Apache License 2.0
125 stars 31 forks source link

Tags : infinite loop #35

Open malletjo opened 8 years ago

malletjo commented 8 years ago

Let me know if i'm wrong :

func getTags(obj reflect.Type, tags map[string]string, key string) {

    if obj.Kind() != reflect.Struct && obj.Kind() != reflect.Ptr {
        return
    }

    var tag string

    fieldsCount := obj.NumField()

    for i := 0; i < fieldsCount; i++ {
        structField := obj.Field(i)
        if structField.Anonymous && structField.Type.Kind() == reflect.Struct {
            getTags(obj, tags, key)
        } else {
            tag = structField.Tag.Get(key)
            if tag != "" {
                tags[structField.Name] = tag
            }
        }
    }
}

So if it's another struct, it will call itself with the same tag (obj)

Result in a infinite loop (overflow)

Possible solution: replaced with structField.Type

getTags(structField.Type, tags, key)

=== Step to reproduce ===

In a model

type Model struct {
    aranGO.Document
}

type Event struct {
    Model
    Title string        `json:"title"`
}

The embedded struct should cause the SO

diegogub commented 8 years ago

hi @malletjo , thanks for the report. I will check this now