Skip to content

Commit

Permalink
codes.InvalidArgument when PageSize < 0
Browse files Browse the repository at this point in the history
Fixes #298

Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Mar 29, 2023
1 parent 81f602f commit 73a8208
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/backend/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/backend/aio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ func TestBackEnd_ListAioControllers(t *testing.T) {
true,
1000,
},
{
"pagination negative",
"volume-test",
nil,
[]string{},
codes.InvalidArgument,
fmt.Sprintf("negative PageSize is not allowed"),
false,
-10,
},
{
"pagination",
"volume-test",
Expand Down
5 changes: 5 additions & 0 deletions pkg/backend/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/backend/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ func TestBackEnd_ListNullDebugs(t *testing.T) {
true,
1000,
},
{
"pagination negative",
"volume-test",
nil,
[]string{},
codes.InvalidArgument,
fmt.Sprintf("negative PageSize is not allowed"),
false,
-10,
},
{
"pagination",
"volume-test",
Expand Down
5 changes: 5 additions & 0 deletions pkg/backend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/backend/nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ func TestBackEnd_ListNVMfRemoteControllers(t *testing.T) {
true,
1000,
},
{
"pagination negative",
"volume-test",
nil,
[]string{},
codes.InvalidArgument,
fmt.Sprintf("negative PageSize is not allowed"),
false,
-10,
},
{
"pagination",
"volume-test",
Expand Down
5 changes: 5 additions & 0 deletions pkg/frontend/blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/frontend/blk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ func TestFrontEnd_ListVirtioBlks(t *testing.T) {
true,
1000,
},
{
"pagination negative",
"volume-test",
nil,
[]string{},
codes.InvalidArgument,
fmt.Sprintf("negative PageSize is not allowed"),
false,
-10,
},
{
"pagination",
"subsystem-test",
Expand Down
10 changes: 10 additions & 0 deletions pkg/frontend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -443,6 +448,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]
Expand Down
10 changes: 10 additions & 0 deletions pkg/frontend/nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,16 @@ func TestFrontEnd_ListNVMeNamespaces(t *testing.T) {
true,
1000,
},
{
"pagination negative",
"volume-test",
nil,
[]string{},
codes.InvalidArgument,
fmt.Sprintf("negative PageSize is not allowed"),
false,
-10,
},
{
"pagination",
"subsystem-test",
Expand Down
10 changes: 10 additions & 0 deletions pkg/frontend/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/middleend/middleend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/middleend/middleend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,16 @@ func TestMiddleEnd_ListEncryptedVolumes(t *testing.T) {
true,
1000,
},
{
"pagination negative",
"volume-test",
nil,
[]string{},
codes.InvalidArgument,
fmt.Sprintf("negative PageSize is not allowed"),
false,
-10,
},
{
"pagination",
"volume-test",
Expand Down

0 comments on commit 73a8208

Please sign in to comment.