Skip to content

Commit a0ce5e6

Browse files
danpjoeshaw
authored andcommitted
check CanInterface before calling Interface
1 parent ce5db18 commit a0ce5e6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

envdecode.go

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func decode(target interface{}, strict bool) (int, error) {
118118
fallthrough
119119

120120
case reflect.Struct:
121+
if !f.Addr().CanInterface() {
122+
continue
123+
}
124+
121125
ss := f.Addr().Interface()
122126
_, custom := ss.(Decoder)
123127
if custom {

envdecode_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"reflect"
1010
"sort"
1111
"strconv"
12+
"sync"
1213
"testing"
1314
"time"
1415
)
@@ -59,6 +60,8 @@ type testConfig struct {
5960
DefaultSliceInt []int `env:"TEST_UNSET,asdf=asdf,default=1;2;3"`
6061
DefaultDuration time.Duration `env:"TEST_UNSET,asdf=asdf,default=24h"`
6162
DefaultURL *url.URL `env:"TEST_UNSET,default=http://example.com"`
63+
64+
cantInterfaceField sync.Mutex
6265
}
6366

6467
type testConfigNoSet struct {

0 commit comments

Comments
 (0)