From 90cff10e2b84bf28dd858d773e4efe0413da51cf Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 23 Sep 2020 12:00:29 -0700 Subject: [PATCH] avoid crash if disks are not initialized --- cmd/lock-rest-server-common.go | 5 +++-- cmd/lock-rest-server.go | 5 +++++ cmd/storage-rest-server.go | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/lock-rest-server-common.go b/cmd/lock-rest-server-common.go index 15b10e575..074163d69 100644 --- a/cmd/lock-rest-server-common.go +++ b/cmd/lock-rest-server-common.go @@ -42,6 +42,7 @@ const ( ) var ( - errLockConflict = errors.New("lock conflict") - errLockNotExpired = errors.New("lock not expired") + errLockConflict = errors.New("lock conflict") + errLockNotExpired = errors.New("lock not expired") + errLockNotInitialized = errors.New("lock not initialized") ) diff --git a/cmd/lock-rest-server.go b/cmd/lock-rest-server.go index 1b30ef5c6..bfc080229 100644 --- a/cmd/lock-rest-server.go +++ b/cmd/lock-rest-server.go @@ -50,6 +50,11 @@ func (l *lockRESTServer) writeErrorResponse(w http.ResponseWriter, err error) { // IsValid - To authenticate and verify the time difference. func (l *lockRESTServer) IsValid(w http.ResponseWriter, r *http.Request) bool { + if l.ll == nil { + l.writeErrorResponse(w, errLockNotInitialized) + return false + } + if err := storageServerRequestValidate(r); err != nil { l.writeErrorResponse(w, err) return false diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index d2b9c9105..1d4191593 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -102,6 +102,11 @@ func storageServerRequestValidate(r *http.Request) error { // IsValid - To authenticate and verify the time difference. func (s *storageRESTServer) IsValid(w http.ResponseWriter, r *http.Request) bool { + if s.storage == nil { + s.writeErrorResponse(w, errDiskNotFound) + return false + } + if err := storageServerRequestValidate(r); err != nil { s.writeErrorResponse(w, err) return false