From 39d92c796a94150804de6d79cb5c23ee9ca22d76 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Mon, 18 Nov 2019 11:08:52 -0800 Subject: [PATCH] Error instead of panicking if self link isn't long enough (#2672) Merged PR #2672. --- build/terraform | 2 +- build/terraform-beta | 2 +- third_party/terraform/utils/self_link_helpers.go | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 2a828f44e9a5..ee0f7e49dd6b 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 2a828f44e9a5ce5a95223ff295e1d5b739819144 +Subproject commit ee0f7e49dd6be2806377998ba4263571a7ecf94d diff --git a/build/terraform-beta b/build/terraform-beta index 9b2712f9cf58..5e087229861b 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 9b2712f9cf58ebf6f38b1ab9beac863f586d9252 +Subproject commit 5e087229861bbec45b0d6c5b22a1468049d167ae diff --git a/third_party/terraform/utils/self_link_helpers.go b/third_party/terraform/utils/self_link_helpers.go index 4ae779b5abfc..f5cb0893e113 100644 --- a/third_party/terraform/utils/self_link_helpers.go +++ b/third_party/terraform/utils/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 }