From df8d6823eefebc70f5c7333978dfd7da0ede1ede Mon Sep 17 00:00:00 2001 From: Kegsay Date: Wed, 15 Jul 2020 15:26:04 +0100 Subject: [PATCH] Fix panic when uploading keys (#1203) We don't return OTK counts when the client doesn't upload OTKs. --- clientapi/routing/keys.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clientapi/routing/keys.go b/clientapi/routing/keys.go index 8c5c5bbef..56b2faf7b 100644 --- a/clientapi/routing/keys.go +++ b/clientapi/routing/keys.go @@ -82,10 +82,15 @@ func UploadKeys(req *http.Request, keyAPI api.KeyInternalAPI, device *userapi.De JSON: uploadRes.KeyErrors, } } + keyCount := make(map[string]int) + // we only return key counts when the client uploads OTKs + if len(uploadRes.OneTimeKeyCounts) > 0 { + keyCount = uploadRes.OneTimeKeyCounts[0].KeyCount + } return util.JSONResponse{ Code: 200, JSON: struct { OTKCounts interface{} `json:"one_time_key_counts"` - }{uploadRes.OneTimeKeyCounts[0].KeyCount}, + }{keyCount}, } }