From: adr <adr@SDF.ORG>
To: 9fans@9fans.net
Subject: [9fans] Fix sam regexp bug with metacharacters in classes
Date: Tue, 23 Nov 2021 20:26:30 +0000 (UTC) [thread overview]
Message-ID: <171b6946-5a63-f723-b2c9-713ffcfea9e@SDF.ORG> (raw)
The code assumes runes are 16 bits long, not 21, creating faulting
code parsing classes. I.e. '/[\-]' will not match '-'.
This is the same fix already in 9front.
http://adr.freeshell.org/plan9/patches/sam_fix_metachars_on_classes.diff
--- /sys/src/cmd/sam/regexp.c Tue Apr 23 19:06:01 2013
+++ regexp.c Tue Nov 23 15:01:18 2021
@@ -53,8 +53,8 @@
/*
* Actions and Tokens
*
- * 0x100xx are operators, value == precedence
- * 0x200xx are tokens, i.e. operands for operators
+ * 0x2000xx are operators, value == precedence
+ * 0x3000xx are tokens, i.e. operands for operators
*/
enum {
OPERATOR = Runemask+1, /* Bitmask of all operators */
@@ -462,7 +462,8 @@
exprp++;
return '\n';
}
- return *exprp++|(Runemax+1);
+ /* add a flag so metacharacters aren't interpreted */
+ return *exprp++|(Runemask+1);
}
return *exprp++;
}
@@ -498,11 +499,12 @@
if((c2 = nextrec()) == ']')
goto Error;
classp[n+0] = Runemax;
- classp[n+1] = c1;
- classp[n+2] = c2;
+ /* remove possible flag from nextrec() */
+ classp[n+1] = c1 & Runemask;
+ classp[n+2] = c2 & Runemask;
n += 3;
}else
- classp[n++] = c1;
+ classp[n++] = c1 & Runemask;
}
classp[n] = 0;
if(nclass == Nclass){
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Tccbdb20b670003a1-M5d4e6bea6c6908b388e51f0c
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
next reply other threads:[~2021-11-23 20:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 20:26 adr [this message]
2021-11-24 1:28 ` Conor Williams
2021-11-24 1:29 ` Conor Williams
2021-12-25 3:10 ` Conor Williams
2021-12-25 5:35 ` Conor Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=171b6946-5a63-f723-b2c9-713ffcfea9e@SDF.ORG \
--to=adr@sdf.org \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).