Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware Chains - Nil pointer dereference #83

Open
inzanez opened this issue Aug 22, 2018 · 0 comments
Open

Middleware Chains - Nil pointer dereference #83

inzanez opened this issue Aug 22, 2018 · 0 comments

Comments

@inzanez
Copy link

inzanez commented Aug 22, 2018

Hi

I was playing around building different middleware chains on the fly. I was using a slice:
middleware vestigo.Middleware[]
for that purpose. This sometimes resulted in a crash with nil pointer dereference / invalid memory access. I traced it back to a function in 'router.go' in the vestigo package:

func buildChain(f http.HandlerFunc, m ...Middleware) http.HandlerFunc {
    // if our chain is done, use the original handlerfunc
    if len(m) == 0 {
        return f
    }
    // otherwise nest the handlerfuncs
    return m[0](buildChain(f, m[1:cap(m)]...))
}

I replaced the line
return m[0](buildChain(f, m[1:cap(m)]...))
with
return m[0](buildChain(f, m[1:len(m)]...))

on my local sources, now everything is fine. I was wondering why you were using cap here at any rate? Wouldn't using 'len' be safer?

tw1nk added a commit to tw1nk/vestigo that referenced this issue Nov 27, 2018
Middleware Chains - Nil pointer dereference husobee#83
@tw1nk tw1nk mentioned this issue Nov 27, 2018
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

No branches or pull requests

1 participant