pquerna / ffjson

faster JSON serialization for Go
Apache License 2.0
2.97k stars 234 forks source link

nil pointer dereference when unmarshalling time.Time to pointer #257

Open driesdev opened 4 years ago

driesdev commented 4 years ago

the generated code is

            var tmpJSpecialDates *time.Time

            tok = fs.Scan()
            if tok == fflib.FFTok_error {
                goto tokerror
            }
            if tok == fflib.FFTok_right_brace {
                break
            }

            if tok == fflib.FFTok_comma {
                if wantVal == true {
                    // TODO(pquerna): this isn't an ideal error message, this handles
                    // things like [,,,] as an array value.
                    return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
                }
                continue
            } else {
                wantVal = true
            }

            /* handler: tmpJSpecialDates type=*time.Time kind=ptr quoted=false*/

            {
                if tok == fflib.FFTok_null {

                } else {

                    tbuf, err := fs.CaptureField(tok)
                    if err != nil {
                        return fs.WrapErr(err)
                    }

                    err = tmpJSpecialDates.UnmarshalJSON(tbuf)
                    if err != nil {
                        return fs.WrapErr(err)
                    }
                }
                state = fflib.FFParse_after_value
            }

tmpJSpecialDates here never gets assigned a value, hence when UnmarshalJSON is called on it, it causes a panic.