View | Details | Raw Unified | Return to bug 229925 | Differences between
and this patch

Collapse All | Expand All

(-)b/contrib/netbsd-tests/lib/libc/regex/data/meta.in (-1 / +3 lines)
Lines 4-10 a[bc]d & abd abd Link Here
4
a\*c		&	a*c	a*c
4
a\*c		&	a*c	a*c
5
a\\b		&	a\b	a\b
5
a\\b		&	a\b	a\b
6
a\\\*b		&	a\*b	a\*b
6
a\\\*b		&	a\*b	a\*b
7
a\bc		&	abc	abc
7
# Begin FreeBSD
8
a\bc		&C	EESCAPE
9
# End FreeBSD
8
a\		&C	EESCAPE
10
a\		&C	EESCAPE
9
a\\bc		&	a\bc	a\bc
11
a\\bc		&	a\bc	a\bc
10
\{		bC	BADRPT
12
\{		bC	BADRPT
(-)b/lib/libc/regex/regcomp.c (-2 / +46 lines)
Lines 132-137 static void p_b_cclass(struct parse *p, cset *cs); Link Here
132
static void p_b_eclass(struct parse *p, cset *cs);
132
static void p_b_eclass(struct parse *p, cset *cs);
133
static wint_t p_b_symbol(struct parse *p);
133
static wint_t p_b_symbol(struct parse *p);
134
static wint_t p_b_coll_elem(struct parse *p, wint_t endc);
134
static wint_t p_b_coll_elem(struct parse *p, wint_t endc);
135
static int may_escape(struct parse *p, const wint_t ch);
135
static wint_t othercase(wint_t ch);
136
static wint_t othercase(wint_t ch);
136
static void bothcases(struct parse *p, wint_t ch);
137
static void bothcases(struct parse *p, wint_t ch);
137
static void ordinary(struct parse *p, wint_t ch);
138
static void ordinary(struct parse *p, wint_t ch);
Lines 441-447 p_ere_exp(struct parse *p, struct branchc *bc) Link Here
441
			EMIT(OEOW, 0);
442
			EMIT(OEOW, 0);
442
			break;
443
			break;
443
		default:
444
		default:
444
			ordinary(p, wc);
445
			if (may_escape(p, wc) == 0)
446
				ordinary(p, wc);
447
			else
448
				SETERROR(REG_EESCAPE);
445
			break;
449
			break;
446
		}
450
		}
447
		break;
451
		break;
Lines 450-456 p_ere_exp(struct parse *p, struct branchc *bc) Link Here
450
			return (false);
454
			return (false);
451
		p->next--;
455
		p->next--;
452
		wc = WGETNEXT();
456
		wc = WGETNEXT();
453
		ordinary(p, wc);
457
		/*  Throw an error if we're not dealing with an escapable */
458
		if (c&BACKSL && may_escape(p, wc) != 0)
459
			SETERROR(REG_EESCAPE);
460
		else
461
			ordinary(p, wc);
454
		break;
462
		break;
455
	}
463
	}
456
464
Lines 1100-1105 p_b_coll_elem(struct parse *p, Link Here
1100
	return(0);
1108
	return(0);
1101
}
1109
}
1102
1110
1111
/*
1112
 - may_escape - determine whether 'ch' is escape-able in the current context
1113
 == static int may_escape(struct parse *p, const wint_t ch)
1114
 */
1115
static int
1116
may_escape(struct parse *p, const wint_t ch)
1117
{
1118
	/*
1119
	 * Build a whitelist of characters that may be escaped to produce an
1120
	 * ordinary in the current context. This assumes that these have not
1121
	 * been otherwise interpreted as a special character. Escaping an
1122
	 * ordinary character yields undefined results according to
1123
	 * IEEE 1003.1-2008. Some extensions (notably, some GNU extensions) take
1124
	 * advantage of this and use escaped ordinary characters to provide
1125
	 * special meaning, e.g. \b, \B, \w, \W, \s, \S.
1126
	 */
1127
	switch(ch) {
1128
	case '+':
1129
	case '?':
1130
		/* The above characters may not be escaped in BREs */
1131
		if (!(p->g->cflags&REG_EXTENDED))
1132
			return 1;
1133
		/* Fallthrough */
1134
	case '.':
1135
	case '[':
1136
	case ']':
1137
	case '\\':
1138
	case '*':
1139
	case '^':
1140
	case '$':
1141
		return 0;
1142
	default:
1143
		return 1;
1144
	}
1145
}
1146
1103
/*
1147
/*
1104
 - othercase - return the case counterpart of an alphabetic
1148
 - othercase - return the case counterpart of an alphabetic
1105
 == static wint_t othercase(wint_t ch);
1149
 == static wint_t othercase(wint_t ch);
(-)b/lib/libc/regex/regerror.c (-1 / +1 lines)
Lines 92-98 static struct rerr { Link Here
92
	{REG_BADPAT,	"REG_BADPAT",	"invalid regular expression"},
92
	{REG_BADPAT,	"REG_BADPAT",	"invalid regular expression"},
93
	{REG_ECOLLATE,	"REG_ECOLLATE",	"invalid collating element"},
93
	{REG_ECOLLATE,	"REG_ECOLLATE",	"invalid collating element"},
94
	{REG_ECTYPE,	"REG_ECTYPE",	"invalid character class"},
94
	{REG_ECTYPE,	"REG_ECTYPE",	"invalid character class"},
95
	{REG_EESCAPE,	"REG_EESCAPE",	"trailing backslash (\\)"},
95
	{REG_EESCAPE,	"REG_EESCAPE",	"invalid escape sequence or trailing backslash (\\)"},
96
	{REG_ESUBREG,	"REG_ESUBREG",	"invalid backreference number"},
96
	{REG_ESUBREG,	"REG_ESUBREG",	"invalid backreference number"},
97
	{REG_EBRACK,	"REG_EBRACK",	"brackets ([ ]) not balanced"},
97
	{REG_EBRACK,	"REG_EBRACK",	"brackets ([ ]) not balanced"},
98
	{REG_EPAREN,	"REG_EPAREN",	"parentheses not balanced"},
98
	{REG_EPAREN,	"REG_EPAREN",	"parentheses not balanced"},

Return to bug 229925