Skip to content

Commit

Permalink
Fix panic serving index file if HTTP request is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed May 27, 2019
1 parent b590613 commit 14a8ffe
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions caddyhttp/httpserver/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func (c ConfigSelector) Select(r *http.Request) (config HandlerConfig) {
// path separator, just like URLs. IndexFle handles path manipulation
// internally for systems that use different path separators.
func IndexFile(root http.FileSystem, fpath string, indexFiles []string) (string, bool) {
if len(fpath) == 0 {
// https://caddy.community/t/panic-runtime-error-index-out-of-range/5781
fpath = "/"
}
if fpath[len(fpath)-1] != '/' || root == nil {
return "", false
}
Expand Down

0 comments on commit 14a8ffe

Please sign in to comment.