From e999110be1955e941932943e772cf22d62929513 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 3 Apr 2020 18:23:24 +0300 Subject: [PATCH] object: prevent potential NPE panic in PutRequest.CID method --- object/service.go | 4 +++- object/service_test.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/object/service.go b/object/service.go index 3a2ca08..ab3bf5f 100644 --- a/object/service.go +++ b/object/service.go @@ -127,7 +127,9 @@ func (m *PutRequest) NotFull() bool { return checkIsNotFull(m) } // CID returns container id value from object put request. func (m *PutRequest) CID() CID { if header := m.GetHeader(); header != nil { - return header.Object.SystemHeader.CID + if obj := header.GetObject(); obj != nil { + return obj.SystemHeader.CID + } } return refs.CID{} } diff --git a/object/service_test.go b/object/service_test.go index 46213e2..f38e2ed 100644 --- a/object/service_test.go +++ b/object/service_test.go @@ -16,6 +16,7 @@ func TestRequest(t *testing.T) { &DeleteRequest{}, &GetRangeRequest{}, &GetRangeHashRequest{}, + MakePutRequestHeader(nil, nil), } types := []RequestType{ @@ -26,6 +27,7 @@ func TestRequest(t *testing.T) { RequestDelete, RequestRange, RequestRangeHash, + RequestPut, } for i := range cases {