Bug 666540 — Segfault on empty e-mail addresses with potential match
authorPhilip Withnall <philip@tecnocode.co.uk>
Wed, 21 Dec 2011 20:09:47 +0000 (20:09 +0000)
committerPhilip Withnall <philip@tecnocode.co.uk>
Wed, 21 Dec 2011 20:11:20 +0000 (20:11 +0000)
Gracefully handle invalid e-mail addresses (such as empty strings or strings
not containing an ‘@’) when searching for potential matches.

Closes: bgo#666540

NEWS
folks/potential-match.vala

diff --git a/NEWS b/NEWS
index eee9353..1cfc30a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Overview of changes from libfolks 0.6.6 to libfolks 0.6.7
 Bugs fixed:
 * Bug 666310 — Crash in Tracker backend by unsetting an entry in a read-only map
 * Bug 666528 — Can't convert from type 'GFile' to 'gchararray'
+* Bug 666540 — Segfault on empty e-mail addresses with potential match
 
 Overview of changes from libfolks 0.6.5 to libfolks 0.6.6
 =============================================================
index 82e2e13..eb4906c 100644 (file)
@@ -254,11 +254,31 @@ public class Folks.PotentialMatch : Object
 
       foreach (var fd_a in set_a)
         {
+          string[] email_split_a = fd_a.value.split ("@");
+
+          /* Sanity check for valid e-mail addresses. */
+          if (email_split_a.length < 2)
+            {
+              warning ("Invalid e-mail address when looking for potential " +
+                  "match: %s", fd_a.value);
+              continue;
+            }
+
+          string[] tokens_a =
+            email_split_a[0].split_set (this._SEPARATORS);
+
           foreach (var fd_b in set_b)
             {
-              string[] email_split_a = fd_a.value.split ("@");
               string[] email_split_b = fd_b.value.split ("@");
 
+              /* Sanity check for valid e-mail addresses. */
+              if (email_split_b.length < 2)
+                {
+                  warning ("Invalid e-mail address when looking for " +
+                      "potential match: %s", fd_b.value);
+                  continue;
+                }
+
               if (fd_a.value == fd_b.value)
                 {
                   if (PotentialMatch.known_email_aliases.contains
@@ -277,8 +297,6 @@ public class Folks.PotentialMatch : Object
                 }
               else
                 {
-                  string[] tokens_a =
-                    email_split_a[0].split_set (this._SEPARATORS);
                   string[] tokens_b =
                     email_split_b[0].split_set (this._SEPARATORS);