[prev in list] [next in list] [prev in thread] [next in thread] 

List:       9fans
Subject:    Re: [9fans] Fix sam regexp bug with metacharacters in classes
From:       Conor Williams <conor.williams () gmail ! com>
Date:       2021-11-24 1:29:31
Message-ID: CAL6pNZ-LSyfbjjqMeA_48agb_rzF_8zfszy4=Rz=kPVXro5GWg () mail ! gmail ! com
[Download RAW message or body]

sorry that s should have a k preceding _ /c:2021248pm

On Wed, Nov 24, 2021 at 1:28 AM Conor Williams <conor.williams@gmail.com>
wrote:

> why on Gaia do you not have a
> Runemas_Incremented_By_One_To_Keep_A_Negative_Sub
> variable?
> apart from that, it looks okay... will tango it in later...
>
> /c:2022November!^N^M
>
> On Tue, Nov 23, 2021 at 8:27 PM adr <adr@sdf.org> wrote:
>
>> 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-M5540075cb6bb20848c0e586d
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[Attachment #3 (text/html)]

<html><html><div dir="ltr">sorry that s should have a k preceding _ /c:2021248pm<br \
/></div><br /><div class="gmail_quote"><div class="gmail_attr" dir="ltr">On Wed, Nov \
24, 2021 at 1:28 AM Conor Williams &lt;<a \
href="mailto:conor.williams@gmail.com">conor.williams@gmail.com</a>&gt; wrote:<br \
/></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
dir="ltr"><div>why on Gaia do you not have a \
Runemas_Incremented_By_One_To_Keep_A_Negative_Sub</div><div>variable?</div><div>apart \
from that, it looks okay... will tango it in later...</div><div><br \
/></div><div>/c:2022November!^N^M<br /></div></div><br /><div \
class="gmail_quote"><div class="gmail_attr" dir="ltr">On Tue, Nov 23, 2021 at 8:27 PM \
adr &lt;<a href="mailto:adr@sdf.org" target="_blank">adr@sdf.org</a>&gt; wrote:<br \
/></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The code assumes runes \
are 16 bits long, not 21, creating faulting<br /> code parsing classes. I.e. \
&#39;/[\-]&#39; will not match &#39;-&#39;.<br /><br /> This is the same fix already \
in 9front.<br /><br /><a \
href="http://adr.freeshell.org/plan9/patches/sam_fix_metachars_on_classes.diff" \
rel="noreferrer" target="_blank">http://adr.freeshell.org/plan9/patches/sam_fix_metachars_on_classes.diff</a><br \
                /><br />
--- /sys/src/cmd/sam/regexp.c&nbsp; &nbsp;Tue Apr 23 19:06:01 2013<br />
+++ regexp.c&nbsp; &nbsp; Tue Nov 23 15:01:18 2021<br />
@@ -53,8 +53,8 @@<br />
&nbsp; /*<br />
&nbsp; &nbsp;* Actions and Tokens<br />
&nbsp; &nbsp;*<br />
- *&nbsp; &nbsp; &nbsp;0x100xx are operators, value == precedence<br />
- *&nbsp; &nbsp; &nbsp;0x200xx are tokens, i.e. operands for operators<br />
+ *&nbsp; &nbsp; &nbsp;0x2000xx are operators, value == precedence<br />
+ *&nbsp; &nbsp; &nbsp;0x3000xx are tokens, i.e. operands for operators<br />
&nbsp; &nbsp;*/<br />
&nbsp; enum {<br />
&nbsp; &nbsp; &nbsp; &nbsp; OPERATOR = Runemask+1,&nbsp; /* Bitmask of all operators \
*/<br /> @@ -462,7 +462,8 @@<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
exprp++;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; return &#39;\n&#39;;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
                &nbsp; &nbsp; }<br />
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return \
*exprp++|(Runemax+1);<br /> +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;/* add a flag so metacharacters aren&#39;t interpreted */<br /> +&nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return *exprp++|(Runemask+1);<br /> &nbsp; \
&nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; return *exprp++;<br />
&nbsp; }<br />
@@ -498,11 +499,12 @@<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
if((c2 = nextrec()) == &#39;]&#39;)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; goto Error;<br \
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
                &nbsp; classp[n+0] = Runemax;<br />
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
                &nbsp;classp[n+1] = c1;<br />
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;classp[n+2] = c2;<br /> +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* remove possible flag from nextrec() */<br /> \
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;classp[n+1] = c1 &amp; Runemask;<br /> +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;classp[n+2] = c2 &amp; Runemask;<br \
/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; n += 3;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else<br \
                />
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;classp[n++] = c1;<br /> +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;classp[n++] = c1 &amp; Runemask;<br /> &nbsp; \
&nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; classp[n] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(nclass == Nclass){<br /><br /><br />
------------------------------------------<br />
9fans: 9fans<br />
Permalink: <a href="https://9fans.topicbox.com/groups/9fans/Tccbdb20b670003a1-M5d4e6bea6c6908b388e51f0c" \
rel="noreferrer" target="_blank">https://9fans.topicbox.com/groups/9fans/Tccbdb20b670003a1-M5d4e6bea6c6908b388e51f0c</a><br \
/> Delivery options: <a href="https://9fans.topicbox.com/groups/9fans/subscription" \
rel="noreferrer" target="_blank">https://9fans.topicbox.com/groups/9fans/subscription</a><br \
/></blockquote></div></blockquote></div></html><div id="topicbox-footer" \
style="margin:10px 0 0;border-top:1px solid \
#ddd;border-color:rgba(0,0,0,.15);padding:7px 0;">

<strong><a href="https://9fans.topicbox.com/latest" \
style="color:inherit;text-decoration:none">9fans</a></strong>  / 9fans / see
<a href="https://9fans.topicbox.com/groups/9fans">discussions</a>
  +
<a href="https://9fans.topicbox.com/groups/9fans/members">participants</a>
  +
<a href="https://9fans.topicbox.com/groups/9fans/subscription">delivery&nbsp;options</a>
 <a href="https://9fans.topicbox.com/groups/9fans/Tccbdb20b670003a1-M5540075cb6bb20848c0e586d" \
style="float:right">Permalink</a> </div>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic