From 46215c3619b3ab024ea38ad42c2c926478737e70 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 13 Nov 2019 17:45:53 +0000 Subject: [PATCH] Error instead of panicking if self link isn't long enough Signed-off-by: Modular Magician --- google/self_link_helpers.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/google/self_link_helpers.go b/google/self_link_helpers.go index 4ae779b5abf..f5cb0893e11 100644 --- a/google/self_link_helpers.go +++ b/google/self_link_helpers.go @@ -143,6 +143,14 @@ func GetLocationalResourcePropertiesFromSelfLinkString(selfLink string) (string, } s := strings.Split(parsed.Path, "/") + + // This is a pretty bad way to tell if this is a self link, but stops us + // from accessing an index out of bounds and causing a panic. generally, we + // expect bad values to be partial URIs and names, so this will catch them + if len(s) < 9 { + return "", "", "", fmt.Errorf("value %s was not a self link", selfLink) + } + return s[4], s[6], s[8], nil }