@@ -47,7 +47,8 @@ import (
4747)
4848
4949const (
50- LogLevelDebug = "debug"
50+ LogLevelDebug = "debug"
51+ headerKeyValuePairElements = 2
5152)
5253
5354type flags struct {
@@ -437,10 +438,14 @@ func grpcConn(reg prometheus.Registerer, flags flags) (*grpc.ClientConn, error)
437438 streamInterceptors := []grpc.StreamClientInterceptor {}
438439
439440 if len (flags .Upload .GRPCHeaders ) > 0 {
440- unaryInterceptors = append ([]grpc.UnaryClientInterceptor {
441- customHeadersUnaryInterceptor (flags .Upload .GRPCHeaders )}, unaryInterceptors ... )
442- streamInterceptors = append ([]grpc.StreamClientInterceptor {
443- customHeadersStreamInterceptor (flags .Upload .GRPCHeaders )}, streamInterceptors ... )
441+ unaryInterceptors = append (
442+ []grpc.UnaryClientInterceptor {customHeadersUnaryInterceptor (flags .Upload .GRPCHeaders )},
443+ unaryInterceptors ... ,
444+ )
445+ streamInterceptors = append (
446+ []grpc.StreamClientInterceptor {customHeadersStreamInterceptor (flags .Upload .GRPCHeaders )},
447+ streamInterceptors ... ,
448+ )
444449 }
445450
446451 opts := []grpc.DialOption {
@@ -495,19 +500,23 @@ func (t *perRequestBearerToken) RequireTransportSecurity() bool {
495500
496501func customHeadersUnaryInterceptor (headers map [string ]string ) grpc.UnaryClientInterceptor {
497502 return func (ctx context.Context , method string , req , reply interface {}, cc * grpc.ClientConn , invoker grpc.UnaryInvoker , opts ... grpc.CallOption ) error {
503+ kvPairs := make ([]string , 0 , len (headers )* headerKeyValuePairElements )
498504 for key , value := range headers {
499- ctx = metadata . AppendToOutgoingContext ( ctx , key , value )
505+ kvPairs = append ( kvPairs , key , value )
500506 }
501- return invoker (ctx , method , req , reply , cc , opts ... )
507+ newCtx := metadata .AppendToOutgoingContext (ctx , kvPairs ... )
508+ return invoker (newCtx , method , req , reply , cc , opts ... )
502509 }
503510}
504511
505512func customHeadersStreamInterceptor (headers map [string ]string ) grpc.StreamClientInterceptor {
506513 return func (ctx context.Context , desc * grpc.StreamDesc , cc * grpc.ClientConn , method string , streamer grpc.Streamer , opts ... grpc.CallOption ) (grpc.ClientStream , error ) {
514+ kvPairs := make ([]string , 0 , len (headers )* headerKeyValuePairElements )
507515 for key , value := range headers {
508- ctx = metadata . AppendToOutgoingContext ( ctx , key , value )
516+ kvPairs = append ( kvPairs , key , value )
509517 }
510- return streamer (ctx , desc , cc , method , opts ... )
518+ newCtx := metadata .AppendToOutgoingContext (ctx , kvPairs ... )
519+ return streamer (newCtx , desc , cc , method , opts ... )
511520 }
512521}
513522
@@ -618,7 +627,7 @@ func getNoteHexString(sectionBytes []byte, name string, noteType uint32) (string
618627
619628 // read descsz and compute the last index of the note data
620629 dataSize := binary .LittleEndian .Uint32 (sectionBytes [idx - 4 : idx ])
621- idxDataEnd := uint64 (idxDataStart ) + uint64 (dataSize ) //nolint:gosec
630+ idxDataEnd := uint64 (idxDataStart ) + uint64 (dataSize ) //nolint:gosec // checked below
622631
623632 // Check sanity (64 is totally arbitrary, as we only use it for Linux ID and Build ID)
624633 if idxDataEnd > uint64 (len (sectionBytes )) || dataSize > 64 {
0 commit comments