From a8c1dc1402efd9bc06fa5217acf5fb99b9ae1063 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Mon, 16 Jan 2017 16:28:48 +0100
Subject: [PATCH] rcfile: don't accept empty regexes for syntax coloring

As a small service to the user, reject empty regex strings,
because an entirely empty regex simply doesn't make sense.

Inspired-by: Elia Geretto <elia.f.geretto@gmail.com>
---
 src/rcfile.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/rcfile.c b/src/rcfile.c
index 372482c2..42c21df1 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -701,7 +701,11 @@ void parse_colors(char *ptr, int rex_flags)
 	if (ptr == NULL)
 	    break;
 
-	goodstart = nregcomp(fgstr, rex_flags);
+	if (*fgstr == '\0') {
+	    rcfile_error(N_("Empty regex string"));
+	    goodstart = FALSE;
+	} else
+	    goodstart = nregcomp(fgstr, rex_flags);
 
 	/* If the starting regex is valid, initialize a new color struct,
 	 * and hook it in at the tail of the linked list. */
@@ -751,6 +755,11 @@ void parse_colors(char *ptr, int rex_flags)
 	if (ptr == NULL)
 	    break;
 
+	if (*fgstr == '\0') {
+	    rcfile_error(N_("Empty regex string"));
+	    continue;
+	}
+
 	/* If the start regex was invalid, skip past the end regex
 	 * to stay in sync. */
 	if (!goodstart)
-- 
GitLab