Skip to content

Commit a590352

Browse files
committed
Check indexes in dbmem
Might have no match, and a -1 will panic.
1 parent 171dc79 commit a590352

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,8 @@ func (q *FakeQuerier) DeleteOAuth2ProviderAppTokensByAppAndUserID(_ context.Cont
13121312
keyIdx := slices.IndexFunc(q.apiKeys, func(key database.APIKey) bool {
13131313
return key.ID == token.APIKeyID
13141314
})
1315-
if q.oauth2ProviderAppSecrets[secretIdx].AppID == arg.AppID && q.apiKeys[keyIdx].UserID == arg.UserID {
1315+
if secretIdx != -1 && q.oauth2ProviderAppSecrets[secretIdx].AppID == arg.AppID &&
1316+
keyIdx != -1 && q.apiKeys[keyIdx].UserID == arg.UserID {
13161317
keyIDsToDelete = append(keyIDsToDelete, token.APIKeyID)
13171318
} else {
13181319
tokens = append(tokens, token)
@@ -2351,7 +2352,7 @@ func (q *FakeQuerier) GetOAuth2ProviderAppsByUserID(_ context.Context, userID uu
23512352
keyIdx := slices.IndexFunc(q.apiKeys, func(key database.APIKey) bool {
23522353
return key.ID == token.APIKeyID
23532354
})
2354-
if q.apiKeys[keyIdx].UserID == userID {
2355+
if keyIdx != -1 && q.apiKeys[keyIdx].UserID == userID {
23552356
tokens = append(tokens, token)
23562357
}
23572358
}

0 commit comments

Comments
 (0)