From 7601ac2e07dd742e9f229ac001c2a30030b0ee1f Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 11 Jun 2021 12:15:14 +0200 Subject: [PATCH] Fixed invalid cursor iteration within the connection history --- shared/js/connectionlog/History.ts | 35 +++++++++++++----------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/shared/js/connectionlog/History.ts b/shared/js/connectionlog/History.ts index b4225916..4bfb747d 100644 --- a/shared/js/connectionlog/History.ts +++ b/shared/js/connectionlog/History.ts @@ -479,35 +479,30 @@ export class ConnectionHistory { const transaction = this.database.transaction(["attempt-history"], "readonly"); const store = transaction.objectStore("attempt-history"); - const cursor = await new Promise((resolve, reject) => { - const cursor = store.index(targetType === "server-unique-id" ? "serverUniqueId" : "targetAddress").openCursor(target, "prev"); - cursor.onsuccess = () => resolve(cursor.result); - cursor.onerror = () => reject(cursor.error); - }); - - if(!cursor) { - /* We did not find any entry */ - return undefined; - } - + const cursor = store.index(targetType === "server-unique-id" ? "serverUniqueId" : "targetAddress").openCursor(target, "prev"); while(true) { - if(!cursor.value) { + const entry = await new Promise((resolve, reject) => { + cursor.onsuccess = () => resolve(cursor.result); + cursor.onerror = () => reject(cursor.error); + }); + + if(!entry) { return undefined; } - if(cursor.value.serverUniqueId === kUnknownHistoryServerUniqueId && onlySucceeded) { - cursor.continue(); + if(entry.value.serverUniqueId === kUnknownHistoryServerUniqueId && onlySucceeded) { + entry.continue(); continue; } return { - id: cursor.value.id, - timestamp: cursor.value.timestamp, - serverUniqueId: cursor.value.serverUniqueId, + id: entry.value.id, + timestamp: entry.value.timestamp, + serverUniqueId: entry.value.serverUniqueId, - nickname: cursor.value.nickname, - hashedPassword: cursor.value.hashedPassword, - targetAddress: cursor.value.targetAddress, + nickname: entry.value.nickname, + hashedPassword: entry.value.hashedPassword, + targetAddress: entry.value.targetAddress, }; } }