fix(libstatus): make saveContact API memory safe(r)
In https://github.com/status-im/status-desktop/commit/31a9d1a6f we've fixed a bug where a contact's thumbnail hasn't been passed to the `saveContact` API. Unfortunately, that fix wasn't memory safe. There are cases when a contact's `identityImage` is `nil`, resulting in illegal storage access when accessing a contact's thumbnail. This commit fixes the issue by safe guarding around `identityImage` possibly being `nil`.
This commit is contained in:
parent
7b07a31fa6
commit
3615a16b70
|
@ -81,9 +81,15 @@ proc addContact*(self: ContactModel, id: string, localNickname: string): string
|
|||
""
|
||||
else:
|
||||
localNickname
|
||||
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.identityImage.thumbnail, contact.systemTags, nickname)
|
||||
|
||||
var thumbnail = ""
|
||||
if contact.identityImage != nil:
|
||||
thumbnail = contact.identityImage.thumbnail
|
||||
|
||||
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, thumbnail, contact.systemTags, nickname)
|
||||
self.events.emit("contactAdded", Args())
|
||||
discard requestContactUpdate(contact.id)
|
||||
|
||||
if updating:
|
||||
let profile = Profile(
|
||||
id: contact.id,
|
||||
|
@ -106,7 +112,12 @@ proc addContact*(self: ContactModel, id: string): string =
|
|||
proc removeContact*(self: ContactModel, id: string) =
|
||||
let contact = self.getContactByID(id)
|
||||
contact.systemTags.delete(contact.systemTags.find(":contact/added"))
|
||||
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.identityImage.thumbnail, contact.systemTags, contact.localNickname)
|
||||
|
||||
var thumbnail = ""
|
||||
if contact.identityImage != nil:
|
||||
thumbnail = contact.identityImage.thumbnail
|
||||
|
||||
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, thumbnail, contact.systemTags, contact.localNickname)
|
||||
self.events.emit("contactRemoved", Args())
|
||||
|
||||
proc isAdded*(self: ContactModel, id: string): bool =
|
||||
|
|
Loading…
Reference in New Issue