From 7ebb02c556ec8739421750314ee9b1309a2306ed Mon Sep 17 00:00:00 2001 From: Andrew Lytvynov Date: Tue, 14 Jul 2020 15:12:04 -0700 Subject: [PATCH] Fix a nil pointer dereference in firestore index creation https://github.com/gravitational/teleport/pull/3766 removed a nil pointer check when creating firestore indexes. This was a legitimate check, for when indexes already exist. Tested this manually. Unit testing is trickier because the firestore emulator in gcloud doesn't support indexes. --- lib/backend/firestore/firestorebk.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/backend/firestore/firestorebk.go b/lib/backend/firestore/firestorebk.go index b1a1934652778..7182071ec5fce 100644 --- a/lib/backend/firestore/firestorebk.go +++ b/lib/backend/firestore/firestorebk.go @@ -712,11 +712,14 @@ func EnsureIndexes(ctx context.Context, adminSvc *apiv1.FirestoreAdminClient, tu return ConvertGRPCError(err) } - meta := adminpb.IndexOperationMetadata{} - if err := proto.Unmarshal(operation.Metadata.Value, &meta); err != nil { - return trace.Wrap(err) + // operation can be nil if error code is codes.AlreadyExists. + if operation != nil { + meta := adminpb.IndexOperationMetadata{} + if err := proto.Unmarshal(operation.Metadata.Value, &meta); err != nil { + return trace.Wrap(err) + } + tuplesToIndexNames[tuple] = meta.Index } - tuplesToIndexNames[tuple] = meta.Index } // Instead of polling the Index state, we should wait for the Operation to