1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

Fix panic serving index file if HTTP request is malformed

This commit is contained in:
Matthew Holt 2019-05-27 08:12:19 -06:00
parent b5906135c7
commit 14a8ffedd8
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -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
}