aboutsummaryrefslogtreecommitdiffstats
path: root/regexp/jimregexp.c
diff options
context:
space:
mode:
Diffstat (limited to 'regexp/jimregexp.c')
-rw-r--r--regexp/jimregexp.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/regexp/jimregexp.c b/regexp/jimregexp.c
index e3fe4fc05..7fd6d473e 100644
--- a/regexp/jimregexp.c
+++ b/regexp/jimregexp.c
@@ -723,7 +723,7 @@ static int regatom(regex_t *preg, int *flagp)
pattern++;
}
- while (*pattern && *pattern != ']') {
+ while (*pattern != ']') {
/* Is this a range? a-z */
int start;
int end;
@@ -735,6 +735,11 @@ static int regatom(regex_t *preg, int *flagp)
};
int cc;
+ if (!*pattern) {
+ preg->err = REG_ERR_UNMATCHED_BRACKET;
+ return 0;
+ }
+
pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
if (start == '\\') {
/* First check for class shorthand escapes */
@@ -758,6 +763,10 @@ static int regatom(regex_t *preg, int *flagp)
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
+ if (start == '\\' && *pattern == 0) {
+ preg->err = REG_ERR_INVALID_ESCAPE;
+ return 0;
+ }
}
if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
/* skip '-' */
@@ -769,6 +778,10 @@ static int regatom(regex_t *preg, int *flagp)
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
+ if (start == '\\' && *pattern == 0) {
+ preg->err = REG_ERR_INVALID_ESCAPE;
+ return 0;
+ }
}
reg_addrange(preg, start, end);
@@ -873,7 +886,7 @@ cc_switch:
ch = *preg->regparse++;
switch (ch) {
case '\0':
- preg->err = REG_ERR_TRAILING_BACKSLASH;
+ preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
case 'A':
ret = regnode(preg, BOLX);
@@ -1883,9 +1896,10 @@ size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_s
"nested count",
"internal error",
"count follows nothing",
- "trailing backslash",
+ "invalid escape \\ sequence",
"corrupted program",
"contains null char",
+ "brackets [] not balanced",
};
const char *err;