Problem with setting substring match variables (%{1} etc.)

Arran Cudbard-Bell A.Cudbard-Bell at sussex.ac.uk
Wed Aug 8 12:42:10 CEST 2007


Enrik Berkhan wrote:
> Hi,
>
> there seems to be a subtle problem with setting the substring match
> variables like %{1} etc. when an optionally matching subexpression does
> not match, but the expression as a whole does.
>
> Example:
>
> The expression ^(a|b)?(.)$ will match for example 'ax', 'bx', and 'x'.
> The first two cases will work like expected setting %{1} = 'a', %{2} =
> 'x' and so on. In the last case, the first substring is actually empty
> with rxmatch[1].rm_so == -1, but the second substring contains 'x'
> (rxmatch[2].rm_so == 0, rxmatch[2].rm_eo == 1).
>
> The code setting the substring match variables stops on the first
> rxmatch[].rm_so == -1 unless the variable has an old value(?), so %{2}
> might be never set in the last example.
>
> Is this expected behaviour? If not, how can this be fixed? Just leave
> out the 'break' in the for loop? (Code from valuepair.c)
>
>   
>>                 /*
>>                  *      Add %{0}, %{1}, etc.
>>                  */
>>                 for (i = 0; i <= REQUEST_MAX_REGEX; i++) {
>>                         char *p;
>>                         char buffer[sizeof(check->vp_strvalue)];
>>
>>                         /*
>>                          *      Didn't match: delete old
>>                          *      match, if it existed.
>>                          */
>>                         if ((compare != 0) ||
>>                             (rxmatch[i].rm_so == -1)) {
>>                                 p = request_data_get(request, request,
>>                                                      REQUEST_DATA_REGEX | i);
>>                                 if (p) {
>>                                         free(p);
>>                                         continue;
>>                                 }
>>
>>                                 /*
>>                                  *      No previous match
>>                                  *      to delete, stop.
>>                                  */
>>                                 break;
>>                         }
>>                         ...;
>>                 }
>>     
>
> Enrik
> - 
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
>   
Yep I noticed this too, though I worked around it at the time.
Also gets very uggly when you multiple instances of a subcapture group
e.g :

^(a|b){3}(.)$

So you have to write them out in full :

^(a|b)(a|b)(a|b)(.)^

Particularly annoying if your using regular expressions to break apart mac addresses and ip addresses .







More information about the Freeradius-Devel mailing list