Skip to content

Commit 92bfb82

Browse files
authored
Merge pull request #1206 from percona/PBM-1619-fix-sigsegv-for-minio-oss-storages
PBM-1619: Add guards in storage config for minio and oss
2 parents fc11f69 + c3a35a0 commit 92bfb82

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

pbm/storage/mio/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func (cfg *Config) IsSameStorage(other *Config) bool {
9292
}
9393

9494
func (cfg *Config) Cast() error {
95+
if cfg == nil {
96+
return errors.New("missing minio configuration with minio storage type")
97+
}
98+
9599
if cfg.Endpoint == "" {
96100
return errors.New("endpointURL cannot be empty")
97101
}

pbm/storage/mio/config_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ func TestEqual(t *testing.T) {
6969
}
7070

7171
func TestCast(t *testing.T) {
72-
c := &Config{}
72+
var c *Config
73+
err := c.Cast()
74+
if err == nil {
75+
t.Fatal("sigsegv should have happened instead")
76+
}
7377

78+
c = &Config{}
7479
if err := c.Cast(); err == nil {
7580
t.Fatal("want error when EndpointURL is not specified")
7681
}
7782

7883
c.Endpoint = "url"
79-
err := c.Cast()
84+
err = c.Cast()
8085
if err != nil {
8186
t.Fatalf("got error during Cast: %v", err)
8287
}

pbm/storage/oss/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package oss
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

@@ -63,6 +64,9 @@ type Credentials struct {
6364
}
6465

6566
func (cfg *Config) Cast() error {
67+
if cfg == nil {
68+
return errors.New("missing oss configuration with oss storage type")
69+
}
6670
if cfg.Region == "" {
6771
cfg.Region = defaultOSSRegion
6872
}

0 commit comments

Comments
 (0)