For whatever reasons, addressbooks can be corrupt. Clicking on such an
entry in the Contacts overview crashes Evolution with a segmentation
fault. In the overview the first line of the excerpt is empty.
Therefore the return values have to be checked, which is also good
programming practice.
In case of #684175 [1] in
camel_address_unformat (CAMEL_ADDRESS (addr), raw);
according to GDB `raw` is `\000` and returns `FALSE`.
In `camel/camel-internet-address.c`
/**
* camel_internet_address_get:
* @addr: a #CamelInternetAddress object
* @index: address's array index
* @namep: holder for the returned name, or %NULL, if not required.
* @addressp: holder for the returned address, or %NULL, if not required.
*
* Get the address at @index.
*
* Returns: %TRUE if such an address exists, or %FALSE otherwise
**/
gboolean
camel_internet_address_get (CamelInternetAddress *addr,
gint index,
const gchar **namep,
const gchar **addressp)
{
struct _address *a;
g_assert (CAMEL_IS_INTERNET_ADDRESS (addr));
if (index < 0 || index >= ((CamelAddress *) addr)->addresses->len)
return FALSE;
[…]
the check fails here, because `index = 0` and also
`((CamelAddress *) addr)->addresses->len = 0`
that is why `FALSE` is returned.
Therefore check the return address and throw an error instead of
crashing with a segmentation fault.
[1] https://bugzilla.gnome.org/show_bug.cgi?id=684175
---
What should be done in `e_destination_set_contact()` in the error case?
A warning to the user would be nice telling her/him to edit the
addressbook or Evolution should fix up the addressbook entry itself but
also notifying the user.
addressbook/libebook/e-destination.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/addressbook/libebook/e-destination.c b/addressbook/libebook/e-destination.c
index 96582d1..9808fe8 100644
--- a/addressbook/libebook/e-destination.c
+++ b/addressbook/libebook/e-destination.c
@@ -463,8 +463,13 @@ e_destination_set_contact (EDestination *dest,
raw = e_vcard_attribute_get_value (attr->data);
addr = camel_internet_address_new ();
- camel_address_unformat (CAMEL_ADDRESS (addr), raw);
- camel_internet_address_get (addr, 0, &name, &email);
+ if (camel_address_unformat (CAMEL_ADDRESS (addr), raw) <= 0) {
+ /* Report an error that contact is corrupt */
+ }
+
+ if (!camel_internet_address_get (addr, 0, &name, &email)) {
+ /* Report an error corrupt */
+ }
e_destination_set_name (s_dest, name);
e_destination_set_email (s_dest, email);
--
1.7.10.4
Attachment:
signature.asc
Description: This is a digitally signed message part