Index: /trunk/src/sh_log_evalrule.c
===================================================================
--- /trunk/src/sh_log_evalrule.c	(revision 590)
+++ /trunk/src/sh_log_evalrule.c	(revision 591)
@@ -1051,5 +1051,5 @@
 						sh_string_len(message));
 
-  if (ovecnum > 1)
+  if (ovecnum > 1 && (ovector[0] < ovector[1])) /* guard against patterns using \K */
     {
       retval = sh_string_replace(retval, &(ovector[2]), (ovecnum-1), "___", 3);
Index: /trunk/src/sh_log_parse_apache.c
===================================================================
--- /trunk/src/sh_log_parse_apache.c	(revision 590)
+++ /trunk/src/sh_log_parse_apache.c	(revision 591)
@@ -341,4 +341,17 @@
 
       info->line_ovector = pcre2_get_ovector_pointer(match_data);
+
+      if (info->line_ovector[0] > info->line_ovector[1]) /* guard against patterns using \K */
+	{
+	  char msg[128];
+	  sl_snprintf(msg, sizeof(msg), _("Matching error: start > end"));
+	  
+	  SH_MUTEX_LOCK(mutex_thread_nolog);
+	  sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN,
+			  msg,
+			  _("sh_parse_apache"));
+	  SH_MUTEX_UNLOCK(mutex_thread_nolog);
+	  goto the_end;
+	}
       
       if (info->pos_time > 0)
@@ -450,4 +463,6 @@
     sh_string_destroy(&msg);
   }
+  
+ the_end:
   pcre2_match_data_free(match_data);
   return NULL;
