fix: use `fleetFromString` function to prevent panic for unknown values (#13699)

This commit is contained in:
Igor Sirotin 2024-02-23 10:14:42 +00:00 committed by GitHub
parent 1dc03624d6
commit 28d8145136
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 17 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import sys, os, re import sys, os, re
import sqlcipher3 import sqlcipher3
import readline
from getpass import getpass from getpass import getpass
from common import PasswordFunctions from common import PasswordFunctions

View File

@ -1,4 +1,4 @@
import json, typetraits, tables, sequtils import json, typetraits, tables, sequtils, strutils
type type
Fleet* {.pure.} = enum Fleet* {.pure.} = enum
@ -76,3 +76,9 @@ proc getMailservers*(self: FleetConfiguration, fleet: Fleet): Table[string, stri
result = initTable[string,string]() result = initTable[string,string]()
return return
result = self.fleet[$fleet][fleetKey] result = self.fleet[$fleet][fleetKey]
proc fleetFromString*(fleet: string): Fleet {.inline.} =
try:
return parseEnum[Fleet](fleet)
except:
return Fleet.Undefined

View File

@ -35,7 +35,7 @@ proc init*(self: Controller) =
discard discard
proc getFleet*(self: Controller): string = proc getFleet*(self: Controller): string =
self.nodeConfigurationService.getFleetAsString() return self.nodeConfigurationService.getFleetAsString()
proc changeFleetTo*(self: Controller, fleet: string) = proc changeFleetTo*(self: Controller, fleet: string) =
if (not self.nodeConfigurationService.setFleet(fleet)): if (not self.nodeConfigurationService.setFleet(fleet)):

View File

@ -129,7 +129,7 @@ proc getFleet*(self: Service): Fleet =
result = self.settingsService.getFleet() result = self.settingsService.getFleet()
if result == Fleet.Undefined: if result == Fleet.Undefined:
let fleetFromNodeConfig = self.configuration.ClusterConfig.Fleet let fleetFromNodeConfig = self.configuration.ClusterConfig.Fleet
result = parseEnum[Fleet](fleetFromNodeConfig) result = fleetFromString(fleetFromNodeConfig)
proc getFleetAsString*(self: Service): string = proc getFleetAsString*(self: Service): string =
result = $self.getFleet() result = $self.getFleet()
@ -148,7 +148,7 @@ proc setFleet*(self: Service, fleet: string): bool =
error "error saving fleet ", procName="setFleet" error "error saving fleet ", procName="setFleet"
return false return false
let fleetType = parseEnum[Fleet](fleet) let fleetType = fleetFromString(fleet)
var newConfiguration = self.configuration var newConfiguration = self.configuration
newConfiguration.ClusterConfig.Fleet = fleet newConfiguration.ClusterConfig.Fleet = fleet
newConfiguration.ClusterConfig.BootNodes = self.fleetConfiguration.getNodes(fleetType, FleetNodes.Bootnodes) newConfiguration.ClusterConfig.BootNodes = self.fleetConfiguration.getNodes(fleetType, FleetNodes.Bootnodes)

View File

@ -18,7 +18,7 @@ export stickers_dto
# Default values: # Default values:
const DEFAULT_CURRENCY* = "USD" const DEFAULT_CURRENCY* = "USD"
const DEFAULT_TELEMETRY_SERVER_URL* = "https://telemetry.status.im" const DEFAULT_TELEMETRY_SERVER_URL* = "https://telemetry.status.im"
const DEFAULT_FLEET* = $Fleet.ShardsTest const DEFAULT_FLEET* = Fleet.ShardsTest
# Signals: # Signals:
const SIGNAL_CURRENCY_UPDATED* = "currencyUpdated" const SIGNAL_CURRENCY_UPDATED* = "currencyUpdated"
@ -398,7 +398,7 @@ QtObject:
proc getFleet*(self: Service): Fleet = proc getFleet*(self: Service): Fleet =
let fleetAsString = self.getFleetAsString() let fleetAsString = self.getFleetAsString()
return parseEnum[Fleet](fleetAsString) return fleetFromString(fleetAsString)
proc getCurrentUserStatus*(self: Service): CurrentUserStatus = proc getCurrentUserStatus*(self: Service): CurrentUserStatus =
self.settings.currentUserStatus self.settings.currentUserStatus
@ -413,6 +413,8 @@ QtObject:
return "" return ""
proc pinMailserver*(self: Service, mailserverID: string, fleet: Fleet): bool = proc pinMailserver*(self: Service, mailserverID: string, fleet: Fleet): bool =
if fleet == Fleet.Undefined:
return false
var newMailserverJsonObj = self.settings.pinnedMailserver.pinnedMailserverToJsonNode() var newMailserverJsonObj = self.settings.pinnedMailserver.pinnedMailserverToJsonNode()
newMailserverJsonObj[$fleet] = %* mailserverID newMailserverJsonObj[$fleet] = %* mailserverID
if(self.saveSetting(KEY_PINNED_MAILSERVERS, newMailserverJsonObj)): if(self.saveSetting(KEY_PINNED_MAILSERVERS, newMailserverJsonObj)):

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit ba7faea027b1e87e6d53b0e487df2469cd6271f2 Subproject commit 23ee898754f71341dc53e71657ef0633165f7bd3