Skip to content

Commit 81d9ad4

Browse files
committed
fix: reject negative page-size values in list commands
Signed-off-by: Sypher845 <suyashpatil845@gmail.com>
1 parent 4897b35 commit 81d9ad4

File tree

10 files changed

+41
-0
lines changed

10 files changed

+41
-0
lines changed

cmd/harbor/root/artifact/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ Supports pagination, search queries, and sorting using flags.`,
4343

4444
Args: cobra.MaximumNArgs(1),
4545
RunE: func(cmd *cobra.Command, args []string) error {
46+
if opts.PageSize < 0 {
47+
return fmt.Errorf("page size must be greater than or equal to 0")
48+
}
49+
4650
if opts.PageSize > 100 {
4751
return fmt.Errorf("page size should be less than or equal to 100")
4852
}

cmd/harbor/root/labels/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func ListLabelCommand() *cobra.Command {
3939
Short: "list labels",
4040
Args: cobra.ExactArgs(0),
4141
RunE: func(cmd *cobra.Command, args []string) error {
42+
if opts.PageSize < 0 {
43+
return fmt.Errorf("page size must be greater than or equal to 0")
44+
}
45+
4246
if opts.PageSize > 100 {
4347
return fmt.Errorf("page size should be less than or equal to 100")
4448
}

cmd/harbor/root/project/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func ListProjectCommand() *cobra.Command {
4545
RunE: func(cmd *cobra.Command, args []string) error {
4646
log.Debug("Starting project list command")
4747

48+
if opts.PageSize < 0 {
49+
return fmt.Errorf("page size must be greater than or equal to 0")
50+
}
51+
4852
if opts.PageSize > 100 {
4953
return fmt.Errorf("page size should be less than or equal to 100")
5054
}

cmd/harbor/root/quota/list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func ListQuotaCommand() *cobra.Command {
3131
Short: "list quotas",
3232
Long: "list quotas specified for each project",
3333
Run: func(cmd *cobra.Command, args []string) {
34+
if opts.PageSize < 0 {
35+
log.Errorf("page size must be greater than or equal to 0")
36+
return
37+
}
38+
3439
if opts.PageSize > 100 {
3540
log.Errorf("page size should be less than or equal to 100")
3641
return

cmd/harbor/root/registry/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func ListRegistryCommand() *cobra.Command {
3333
Short: "list registry",
3434
Args: cobra.ExactArgs(0),
3535
RunE: func(cmd *cobra.Command, args []string) error {
36+
if opts.PageSize < 0 {
37+
return fmt.Errorf("page size must be greater than or equal to 0")
38+
}
39+
3640
if opts.PageSize > 100 {
3741
return fmt.Errorf("page size should be less than or equal to 100")
3842
}

cmd/harbor/root/replication/executions/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func ListCommand() *cobra.Command {
5050
rpolicyID = prompt.GetReplicationPolicyFromUser()
5151
}
5252

53+
if opts.PageSize < 0 {
54+
return fmt.Errorf("page size must be greater than or equal to 0")
55+
}
56+
5357
if opts.PageSize > 100 {
5458
return fmt.Errorf("page size should be less than or equal to 100")
5559
}

cmd/harbor/root/replication/policies/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func ListCommand() *cobra.Command {
3333
RunE: func(cmd *cobra.Command, args []string) error {
3434
log.Debug("Starting replications list command")
3535

36+
if opts.PageSize < 0 {
37+
return fmt.Errorf("page size must be greater than or equal to 0")
38+
}
39+
3640
if opts.PageSize > 100 {
3741
return fmt.Errorf("page size should be less than or equal to 100")
3842
}

cmd/harbor/root/repository/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func ListRepositoryCommand() *cobra.Command {
3636
Long: `Get information of all repositories in a project`,
3737
Args: cobra.MaximumNArgs(1),
3838
RunE: func(cmd *cobra.Command, args []string) error {
39+
if opts.PageSize < 0 {
40+
return fmt.Errorf("page size must be greater than or equal to 0")
41+
}
42+
3943
if opts.PageSize > 100 {
4044
return fmt.Errorf("page size should be less than or equal to 100")
4145
}

cmd/harbor/root/schedule/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func ListScheduleCommand() *cobra.Command {
3030
Use: "list",
3131
Short: "show all schedule jobs in Harbor",
3232
RunE: func(cmd *cobra.Command, args []string) error {
33+
if opts.PageSize < 0 {
34+
return fmt.Errorf("page size must be greater than or equal to 0")
35+
}
36+
3337
if opts.PageSize > 100 {
3438
return fmt.Errorf("page size should be less than or equal to 100")
3539
}

cmd/harbor/root/user/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func UserListCmd() *cobra.Command {
3535
Args: cobra.ExactArgs(0),
3636
Aliases: []string{"ls"},
3737
RunE: func(cmd *cobra.Command, args []string) error {
38+
if opts.PageSize < 0 {
39+
return fmt.Errorf("page size must be greater than or equal to 0")
40+
}
41+
3842
if opts.PageSize > 100 {
3943
return fmt.Errorf("page size should be less than or equal to 100")
4044
}

0 commit comments

Comments
 (0)