From e521fc905396260ca8b902385408cb8800f986b6 Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Wed, 29 Mar 2023 03:29:04 +0300 Subject: [PATCH] codes.InvalidArgument when PageSize < 0 Fixes #298 Signed-off-by: Boris Glimcher --- pkg/backend/aio.go | 5 +++++ pkg/backend/aio_test.go | 10 ++++++++++ pkg/backend/null.go | 5 +++++ pkg/backend/null_test.go | 10 ++++++++++ pkg/backend/nvme.go | 5 +++++ pkg/backend/nvme_test.go | 10 ++++++++++ pkg/frontend/blk.go | 5 +++++ pkg/frontend/blk_test.go | 10 ++++++++++ pkg/frontend/nvme.go | 10 ++++++++++ pkg/frontend/nvme_test.go | 19 +++++++++++++++++++ pkg/frontend/scsi.go | 10 ++++++++++ pkg/middleend/middleend.go | 5 +++++ pkg/middleend/middleend_test.go | 10 ++++++++++ 13 files changed, 114 insertions(+) diff --git a/pkg/backend/aio.go b/pkg/backend/aio.go index 6d539e44..b52ac389 100644 --- a/pkg/backend/aio.go +++ b/pkg/backend/aio.go @@ -136,6 +136,11 @@ func (s *Server) UpdateAioController(_ context.Context, in *pb.UpdateAioControll // ListAioControllers lists Aio controllers func (s *Server) ListAioControllers(_ context.Context, in *pb.ListAioControllersRequest) (*pb.ListAioControllersResponse, error) { log.Printf("ListAioControllers: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.BdevGetBdevsResult err := s.rpc.Call("bdev_get_bdevs", nil, &result) if err != nil { diff --git a/pkg/backend/aio_test.go b/pkg/backend/aio_test.go index cb88d530..45caa1bb 100644 --- a/pkg/backend/aio_test.go +++ b/pkg/backend/aio_test.go @@ -348,6 +348,16 @@ func TestBackEnd_ListAioControllers(t *testing.T) { true, 1000, }, + { + "pagination negative", + "volume-test", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", "volume-test", diff --git a/pkg/backend/null.go b/pkg/backend/null.go index 82d767c0..e8f06c7a 100644 --- a/pkg/backend/null.go +++ b/pkg/backend/null.go @@ -136,6 +136,11 @@ func (s *Server) UpdateNullDebug(_ context.Context, in *pb.UpdateNullDebugReques // ListNullDebugs lists Null Debug instances func (s *Server) ListNullDebugs(_ context.Context, in *pb.ListNullDebugsRequest) (*pb.ListNullDebugsResponse, error) { log.Printf("ListNullDebugs: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.BdevGetBdevsResult err := s.rpc.Call("bdev_get_bdevs", nil, &result) if err != nil { diff --git a/pkg/backend/null_test.go b/pkg/backend/null_test.go index 50167dce..776aff7f 100644 --- a/pkg/backend/null_test.go +++ b/pkg/backend/null_test.go @@ -351,6 +351,16 @@ func TestBackEnd_ListNullDebugs(t *testing.T) { true, 1000, }, + { + "pagination negative", + "volume-test", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", "volume-test", diff --git a/pkg/backend/nvme.go b/pkg/backend/nvme.go index f0a158a2..c636d895 100644 --- a/pkg/backend/nvme.go +++ b/pkg/backend/nvme.go @@ -96,6 +96,11 @@ func (s *Server) NVMfRemoteControllerReset(_ context.Context, in *pb.NVMfRemoteC // ListNVMfRemoteControllers lists an NVMf remote controllers func (s *Server) ListNVMfRemoteControllers(_ context.Context, in *pb.ListNVMfRemoteControllersRequest) (*pb.ListNVMfRemoteControllersResponse, error) { log.Printf("ListNVMfRemoteControllers: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.BdevNvmeGetControllerResult err := s.rpc.Call("bdev_nvme_get_controllers", nil, &result) if err != nil { diff --git a/pkg/backend/nvme_test.go b/pkg/backend/nvme_test.go index 9b366d54..5fe769fe 100644 --- a/pkg/backend/nvme_test.go +++ b/pkg/backend/nvme_test.go @@ -289,6 +289,16 @@ func TestBackEnd_ListNVMfRemoteControllers(t *testing.T) { true, 1000, }, + { + "pagination negative", + "volume-test", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", "volume-test", diff --git a/pkg/frontend/blk.go b/pkg/frontend/blk.go index aeeba694..8cb47902 100644 --- a/pkg/frontend/blk.go +++ b/pkg/frontend/blk.go @@ -95,6 +95,11 @@ func (s *Server) UpdateVirtioBlk(_ context.Context, in *pb.UpdateVirtioBlkReques // ListVirtioBlks lists Virtio block devices func (s *Server) ListVirtioBlks(_ context.Context, in *pb.ListVirtioBlksRequest) (*pb.ListVirtioBlksResponse, error) { log.Printf("ListVirtioBlks: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.VhostGetControllersResult err := s.rpc.Call("vhost_get_controllers", nil, &result) if err != nil { diff --git a/pkg/frontend/blk_test.go b/pkg/frontend/blk_test.go index 1d74b9f5..890582ff 100644 --- a/pkg/frontend/blk_test.go +++ b/pkg/frontend/blk_test.go @@ -239,6 +239,16 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) { true, 1000, }, + { + "pagination negative", + "volume-test", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", "subsystem-test", diff --git a/pkg/frontend/nvme.go b/pkg/frontend/nvme.go index 86f051d0..6177f339 100644 --- a/pkg/frontend/nvme.go +++ b/pkg/frontend/nvme.go @@ -160,6 +160,11 @@ func (s *Server) UpdateNVMeSubsystem(_ context.Context, in *pb.UpdateNVMeSubsyst // ListNVMeSubsystems lists NVMe Subsystems func (s *Server) ListNVMeSubsystems(_ context.Context, in *pb.ListNVMeSubsystemsRequest) (*pb.ListNVMeSubsystemsResponse, error) { log.Printf("ListNVMeSubsystems: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.NvmfGetSubsystemsResult err := s.rpc.Call("nvmf_get_subsystems", nil, &result) if err != nil { @@ -447,6 +452,11 @@ func (s *Server) UpdateNVMeNamespace(_ context.Context, in *pb.UpdateNVMeNamespa // ListNVMeNamespaces lists NVMe namespaces func (s *Server) ListNVMeNamespaces(_ context.Context, in *pb.ListNVMeNamespacesRequest) (*pb.ListNVMeNamespacesResponse, error) { log.Printf("ListNVMeNamespaces: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } nqn := "" if in.Parent != "" { subsys, ok := s.Nvme.Subsystems[in.Parent] diff --git a/pkg/frontend/nvme_test.go b/pkg/frontend/nvme_test.go index 8d4d8e70..5840cc8d 100644 --- a/pkg/frontend/nvme_test.go +++ b/pkg/frontend/nvme_test.go @@ -304,6 +304,15 @@ func TestFrontEnd_ListNVMeSubsystem(t *testing.T) { true, 0, }, + { + "pagination negative", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", []*pb.NVMeSubsystem{ @@ -1250,6 +1259,16 @@ func TestFrontEnd_ListNVMeNamespaces(t *testing.T) { true, 1000, }, + { + "pagination negative", + "volume-test", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", "subsystem-test", diff --git a/pkg/frontend/scsi.go b/pkg/frontend/scsi.go index 23a0ac63..7c02d239 100644 --- a/pkg/frontend/scsi.go +++ b/pkg/frontend/scsi.go @@ -73,6 +73,11 @@ func (s *Server) UpdateVirtioScsiController(_ context.Context, in *pb.UpdateVirt // ListVirtioScsiControllers lists Virtio SCSI controllers func (s *Server) ListVirtioScsiControllers(_ context.Context, in *pb.ListVirtioScsiControllersRequest) (*pb.ListVirtioScsiControllersResponse, error) { log.Printf("ListVirtioScsiControllers: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.VhostGetControllersResult err := s.rpc.Call("vhost_get_controllers", nil, &result) if err != nil { @@ -173,6 +178,11 @@ func (s *Server) UpdateVirtioScsiLun(_ context.Context, in *pb.UpdateVirtioScsiL // ListVirtioScsiLuns lists Virtio SCSI LUNs func (s *Server) ListVirtioScsiLuns(_ context.Context, in *pb.ListVirtioScsiLunsRequest) (*pb.ListVirtioScsiLunsResponse, error) { log.Printf("ListVirtioScsiLuns: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.VhostGetControllersResult err := s.rpc.Call("vhost_get_controllers", nil, &result) if err != nil { diff --git a/pkg/middleend/middleend.go b/pkg/middleend/middleend.go index cae017ad..a3680f0b 100644 --- a/pkg/middleend/middleend.go +++ b/pkg/middleend/middleend.go @@ -207,6 +207,11 @@ func (s *Server) UpdateEncryptedVolume(_ context.Context, in *pb.UpdateEncrypted // ListEncryptedVolumes lists encrypted volumes func (s *Server) ListEncryptedVolumes(_ context.Context, in *pb.ListEncryptedVolumesRequest) (*pb.ListEncryptedVolumesResponse, error) { log.Printf("ListEncryptedVolumes: Received from client: %v", in) + if in.PageSize < 0 { + err := status.Error(codes.InvalidArgument, "negative PageSize is not allowed") + log.Printf("error: %v", err) + return nil, err + } var result []models.BdevGetBdevsResult err := s.rpc.Call("bdev_get_bdevs", nil, &result) if err != nil { diff --git a/pkg/middleend/middleend_test.go b/pkg/middleend/middleend_test.go index 6ade3ce4..7020d58e 100644 --- a/pkg/middleend/middleend_test.go +++ b/pkg/middleend/middleend_test.go @@ -528,6 +528,16 @@ func TestMiddleEnd_ListEncryptedVolumes(t *testing.T) { true, 1000, }, + { + "pagination negative", + "volume-test", + nil, + []string{}, + codes.InvalidArgument, + "negative PageSize is not allowed", + false, + -10, + }, { "pagination", "volume-test",