changeset 2277:6c52e4acac3f

Validate / trim location name pattern string better.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 28 Mar 2020 23:25:40 +0200
parents 5e0ee43bff96
children 3293678b598b
files mapsearch.c
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mapsearch.c	Tue Mar 24 09:53:42 2020 +0200
+++ b/mapsearch.c	Sat Mar 28 23:25:40 2020 +0200
@@ -1244,9 +1244,15 @@
     char *pattern = NULL;
     size_t offs1, offs2, slen;
 
+    if (len == 0)
+    {
+        *verr = "Search pattern too short.";
+        goto out;
+    }
+
     // Check search pattern length
     for (offs1 = 0; offs1 < len && th_isspace(data[offs1]); ) offs1++;
-    for (offs2 = len; offs2 > offs1 && (data[offs2] == 0 || th_isspace(data[offs2])); ) offs2--;
+    for (offs2 = len - 1; offs2 > offs1 && (data[offs2] == 0 || th_isspace(data[offs2])); ) offs2--;
 
     slen = offs2 - offs1 + 1;
     if (slen < 2)