On Thu, 14 Oct 2010, Kees Cook wrote:

> I've got a situation where I want to check 2 things before a 3rd thing, but
> the order of the first 2 don't matter. What's the best way to do this?
> 
> Currently, I have two rules, but with the get_ and PAGE_SIZE tests swapped
> between them:
> 
> @cfu_page1@
> position cfu.p;
> expression f, s, I, E1, E2, E3;
> type T;
> @@
> 
>   I =
> (
>   (T)get_zeroed_page(...)
> |
>   (T)__get_free_page(...)
> )
>   ... when != I = E1
> (
>   if ( s != PAGE_SIZE || ... ) { ... return ...; }
> |
>   if ( s >  PAGE_SIZE || ... ) { ... return ...; }
> )
>   ... when != s = E2
>       when != I = E3
>   copy_from_u...@p(I, f, s)
> 
> Instead of the two rules, is there some way to simplify this?

We were originally planning to support a ooo operator that would go 
between two things that should appear in any order, but never got around 
to it.  If you really want to match A ... B ... C and B ... A ... C, ie 
with A and B in the same control-flow path, then I think that two rules is 
the simplest.  If you just want A and B to appear somewhere before C, but 
not necessarily in the same control-flow path, you could do something with 
positions and depends on.  That would require four rules: 1) match 
C and establish a position variable, 2) exists match A ... C, 3) 
exists match B ... C, 4) only consider uses of C whose position satisfied 
both 2 and 3.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to