handlers: Handle crash if r.URL.Path is empty. (#3554)

URL paths can be empty and not have preceding separator,
we do not yet know the conditions this can happen inside
Go http server.

This patch is to ensure that we do not crash ourselves
under conditions where r.URL.Path may be empty.

Fixes #3553
This commit is contained in:
Harshavardhana
2017-01-10 11:01:23 -08:00
committed by GitHub
parent eb6d53d2f5
commit 0563a9235a
3 changed files with 121 additions and 12 deletions
+1 -12
View File
@@ -311,18 +311,7 @@ var notimplementedObjectResourceNames = map[string]bool{
// Resource handler ServeHTTP() wrapper
func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Skip the first element which is usually '/' and split the rest.
splits := strings.SplitN(r.URL.Path[1:], "/", 2)
// Save bucketName and objectName extracted from url Path.
var bucketName, objectName string
if len(splits) == 1 {
bucketName = splits[0]
}
if len(splits) == 2 {
bucketName = splits[0]
objectName = splits[1]
}
bucketName, objectName := urlPath2BucketObjectName(r.URL)
// If bucketName is present and not objectName check for bucket level resource queries.
if bucketName != "" && objectName == "" {