summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-08-07 21:16:12 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-08-07 21:16:12 +0100
commitfd26c7b224e1010df8e4b24d174818b2add39b0b (patch)
tree733997eb94661a3891a727c2a3709135bba2affc /src/modules
parent8884f279758bcad256ed4e5121d1ef8873ecaf81 (diff)
evry - handle invalid chars in filters nicely and stop string walking
possible issue lurking if a utf8 char sequence has invalid content ... avoid it.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/everything/evry_util.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/modules/everything/evry_util.c b/src/modules/everything/evry_util.c
index 6c8c117..cfc8f9d 100644
--- a/src/modules/everything/evry_util.c
+++ b/src/modules/everything/evry_util.c
@@ -49,6 +49,14 @@ evry_util_file_detail_set(Evry_Item_File *file)
49 E_FREE(dir); 49 E_FREE(dir);
50} 50}
51 51
52static inline Eina_Unicode
53_evry_utf8_next(const char *buf, int *iindex)
54{
55 Eina_Unicode u = eina_unicode_utf8_next_get(buf, iindex);
56 if ((!u) || ((u >= 0xdc80) && (u <= 0xdcff))) return 0;
57 return u;
58}
59
52int 60int
53evry_fuzzy_match(const char *str, const char *match) 61evry_fuzzy_match(const char *str, const char *match)
54{ 62{
@@ -131,7 +139,7 @@ evry_fuzzy_match(const char *str, const char *match)
131 ii = 0; 139 ii = 0;
132 /* go to next word */ 140 /* go to next word */
133 for (; (*p != 0) && ((isspace(*p) || (ip && ispunct(*p)))); p += ii) 141 for (; (*p != 0) && ((isspace(*p) || (ip && ispunct(*p)))); p += ii)
134 if (!eina_unicode_utf8_next_get(p, &ii)) break; 142 if (!_evry_utf8_next(p, &ii)) break;
135 cnt++; 143 cnt++;
136 next = p; 144 next = p;
137 m_cnt = 0; 145 m_cnt = 0;
@@ -167,7 +175,7 @@ evry_fuzzy_match(const char *str, const char *match)
167 175
168 /* try next char of match */ 176 /* try next char of match */
169 ii = 0; 177 ii = 0;
170 if (!eina_unicode_utf8_next_get(m, &ii)) continue; 178 if (!_evry_utf8_next(m, &ii)) continue;
171 m += ii; 179 m += ii;
172 if (*m != 0 && !isspace(*m)) 180 if (*m != 0 && !isspace(*m))
173 continue; 181 continue;
@@ -183,7 +191,7 @@ evry_fuzzy_match(const char *str, const char *match)
183 ii = 0; 191 ii = 0;
184 /* go to next match */ 192 /* go to next match */
185 for (; (m[0] && m[ii]) && !isspace(*m); m += ii) 193 for (; (m[0] && m[ii]) && !isspace(*m); m += ii)
186 if (!eina_unicode_utf8_next_get(m, &ii)) break; 194 if (!_evry_utf8_next(m, &ii)) break;
187 } 195 }
188 196
189 if (m_cnt < m_num - 1) 197 if (m_cnt < m_num - 1)
@@ -191,7 +199,7 @@ evry_fuzzy_match(const char *str, const char *match)
191 ii = 0; 199 ii = 0;
192 /* test next match */ 200 /* test next match */
193 for (; (m[0] && m[ii]) && !isspace(*m); m += ii) 201 for (; (m[0] && m[ii]) && !isspace(*m); m += ii)
194 if (!eina_unicode_utf8_next_get(m, &ii)) break; 202 if (!_evry_utf8_next(m, &ii)) break;
195 m_cnt++; 203 m_cnt++;
196 break; 204 break;
197 } 205 }
@@ -203,14 +211,14 @@ evry_fuzzy_match(const char *str, const char *match)
203 !((isspace(*p) || (ip && ispunct(*p)))); 211 !((isspace(*p) || (ip && ispunct(*p))));
204 p += ii) 212 p += ii)
205 { 213 {
206 if (!eina_unicode_utf8_next_get(p, &ii)) break; 214 if (!_evry_utf8_next(p, &ii)) break;
207 } 215 }
208 ii = 0; 216 ii = 0;
209 for (; (p[0] && (s_len - (p - str) >= (unsigned int)ii)) && 217 for (; (p[0] && (s_len - (p - str) >= (unsigned int)ii)) &&
210 ((isspace(*p) || (ip && ispunct(*p)))); 218 ((isspace(*p) || (ip && ispunct(*p))));
211 p += ii) 219 p += ii)
212 { 220 {
213 if (!eina_unicode_utf8_next_get(p, &ii)) break; 221 if (!_evry_utf8_next(p, &ii)) break;
214 } 222 }
215 cnt++; 223 cnt++;
216 next = p; 224 next = p;