[folks] PotentialMatch: prevent out-of-bounds indexing.



commit 7a71777f7ef9b7780ad24c225da47c01b7bdb9e6
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Thu Jan 4 13:06:10 2018 +0100

    PotentialMatch: prevent out-of-bounds indexing.
    
    This fixes a bug where `pos` was larger than the second string's length
    (and for which the out of bounds check came too late).

 folks/potential-match.vala |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
---
diff --git a/folks/potential-match.vala b/folks/potential-match.vala
index ecaf349..f30f743 100644
--- a/folks/potential-match.vala
+++ b/folks/potential-match.vala
@@ -665,12 +665,11 @@ public class Folks.PotentialMatch : Object
     {
       var haystack_len = haystack.length; /* in unichars */
 
-      unichar ch = haystack[pos];
-      if (pos < haystack_len && ch == c)
+      if (pos < haystack_len && haystack[pos] == c)
         return 0;
 
       uint idx = ((int) pos - (int) max_dist).clamp (0, haystack_len - 1);
-      ch = 0;
+      unichar ch = 0;
 
       while (idx < pos + max_dist && (ch = haystack[idx]) != 0)
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]