aboutsummaryrefslogtreecommitdiffstats
path: root/regexp
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2020-07-15 00:38:05 +0000
committerNIIBE Yutaka <[email protected]>2020-07-15 00:44:43 +0000
commit91cb46d948db234be1ea8092f5db9e14294f1b79 (patch)
tree74db351ccb9c9b62c3f72c8c637339cf8963c05d /regexp
parentgpgsm: Make rsaPSS a compliant scheme in de-vs mode. (diff)
downloadgnupg-91cb46d948db234be1ea8092f5db9e14294f1b79.tar.gz
gnupg-91cb46d948db234be1ea8092f5db9e14294f1b79.zip
regexp: Import change from JimTcl.
* regexp/jimregexp.h, regexp/jimregexp.c: Fix from JimTcl. -- Apply the change in JimTcl: commit ac35b8a6ec417f75b5ec86ca64ea1614a8170a38 Author: Steve Bennett <[email protected]> Date: Mon May 4 20:43:46 2020 +1000 regexp: Improved error message Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'regexp')
-rw-r--r--regexp/jimregexp.c20
-rw-r--r--regexp/jimregexp.h3
2 files changed, 19 insertions, 4 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;
diff --git a/regexp/jimregexp.h b/regexp/jimregexp.h
index 581b7104c..ab734797b 100644
--- a/regexp/jimregexp.h
+++ b/regexp/jimregexp.h
@@ -91,9 +91,10 @@ enum {
REG_ERR_NESTED_COUNT,
REG_ERR_INTERNAL,
REG_ERR_COUNT_FOLLOWS_NOTHING,
- REG_ERR_TRAILING_BACKSLASH,
+ REG_ERR_INVALID_ESCAPE,
REG_ERR_CORRUPTED,
REG_ERR_NULL_CHAR,
+ REG_ERR_UNMATCHED_BRACKET,
REG_ERR_NUM
};