fix crash when parsing empty/invalid MC_HOST_* env variable (#2757)

This commit is contained in:
fgma
2019-04-22 21:53:31 +05:30
committed by Nitish Tiwari
parent 83a9d8b91d
commit abceea8fa1
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -231,7 +231,7 @@ func parseEnvURLStr(envURL string) (*url.URL, string, string, *probe.Error) {
res := re.FindAllStringSubmatch(envURL, -1)
// regex will return full match, scheme, accessKey, secretKey and endpoint:port as
// captured groups.
if len(res[0]) != 5 {
if res == nil || len(res[0]) != 5 {
return nil, "", "", err
}
for k, v := range res[0] {
+7
View File
@@ -69,3 +69,10 @@ func TestParseEnvURLStr(t *testing.T) {
}
}
}
func TestParseEnvURLStrInvalid(t *testing.T) {
_, _, _, err := parseEnvURLStr("")
if err == nil {
t.Fatalf("Expected failure")
}
}