aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@NetBSD.org>2023-08-30 20:37:24 +0000
committerEd Maste <emaste@FreeBSD.org>2023-11-08 00:59:51 +0000
commit67264bfe499223cd9864b53975462e3eb57cde2c (patch)
tree9af7ce7ec31ed7fd991e6bf95ab5553058a079b6
parente79edfaf68c542c8545670e911ae83ca0e3493b5 (diff)
downloadsrc-67264bfe499223cd9864b53975462e3eb57cde2c.tar.gz
src-67264bfe499223cd9864b53975462e3eb57cde2c.zip
regcomp: use unsigned char when testing for escapes
- cast GETNEXT to unsigned where it is being promoted to int to prevent sign-extension (really it would have been better for PEEK*() and GETNEXT() to return unsigned char; this would have removed a ton of (uch) casts, but it is too intrusive for now). - fix an isalpha that should have been iswalpha PR: 264275, 274032 Reviewed by: kevans, eugen (previous version) Obtained from: NetBSD (cherry picked from commit 3fb80f1476c7776f04ba7ef6d08397cef6abcfb0) (cherry picked from commit ac695744e2cfb461a64018276fb94999fb0cad9c) Approved by: so Security: FreeBSD-EN-23:14
-rw-r--r--lib/libc/regex/regcomp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index 970a448b649a..bdc1c3379fd3 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -830,10 +830,10 @@ p_simp_re(struct parse *p, struct branchc *bc)
handled = false;
assert(MORE()); /* caller should have ensured this */
- c = GETNEXT();
+ c = (uch)GETNEXT();
if (c == '\\') {
(void)REQUIRE(MORE(), REG_EESCAPE);
- cc = GETNEXT();
+ cc = (uch)GETNEXT();
c = BACKSL | cc;
#ifdef LIBREGEX
if (p->gnuext) {
@@ -994,7 +994,7 @@ p_count(struct parse *p)
int ndigits = 0;
while (MORE() && isdigit((uch)PEEK()) && count <= DUPMAX) {
- count = count*10 + (GETNEXT() - '0');
+ count = count*10 + ((uch)GETNEXT() - '0');
ndigits++;
}
@@ -1304,7 +1304,7 @@ may_escape(struct parse *p, const wint_t ch)
if ((p->pflags & PFLAG_LEGACY_ESC) != 0)
return (true);
- if (isalpha(ch) || ch == '\'' || ch == '`')
+ if (iswalpha(ch) || ch == '\'' || ch == '`')
return (false);
return (true);
#ifdef NOTYET