From 59ac818cba766c566d8bf685fef89e6ea8bb0061 Mon Sep 17 00:00:00 2001 From: Tahmid Hasan Date: Tue, 8 Jan 2019 18:06:54 -0800 Subject: [PATCH] Fix unsafe slice accesses when reading ref annotation --- codegen/method.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen/method.go b/codegen/method.go index d5b5fad99..aa22f4148 100644 --- a/codegen/method.go +++ b/codegen/method.go @@ -289,7 +289,7 @@ func (ms *MethodSpec) scanForNonParams(funcSpec *compile.FunctionSpec) bool { } param, ok := field.Annotations[ms.annotations.HTTPRef] - if !ok || param[0:6] != "params" { + if !ok || strings.HasPrefix(param, "params") { hasNonParams = true return true } @@ -618,7 +618,7 @@ func (ms *MethodSpec) setEndpointRequestHeaderFields( } if param, ok := field.Annotations[ms.annotations.HTTPRef]; ok { - if param[0:8] == "headers." { + if strings.HasPrefix(param, "headers.") { headerName := param[8:] camelHeaderName := CamelCase(headerName) @@ -744,7 +744,7 @@ func (ms *MethodSpec) setResponseHeaderFields( goPrefix string, thriftPrefix string, field *compile.FieldSpec, ) bool { if param, ok := field.Annotations[ms.annotations.HTTPRef]; ok { - if param[0:8] == "headers." { + if strings.HasPrefix(param, "headers.") { headerName := param[8:] ms.ResHeaderFields[headerName] = HeaderFieldInfo{ FieldIdentifier: goPrefix + "." + PascalCase(field.Name), @@ -786,7 +786,7 @@ func (ms *MethodSpec) setClientRequestHeaderFields( } if param, ok := field.Annotations[ms.annotations.HTTPRef]; ok { - if param[0:8] == "headers." { + if strings.HasPrefix(param, "headers.") { headerName := param[8:] bodyIdentifier := goPrefix + "." + PascalCase(field.Name) var headerNameValuePair string