18.11.2014 Views

Anais - Engenharia de Redes de Comunicação - UnB

Anais - Engenharia de Redes de Comunicação - UnB

Anais - Engenharia de Redes de Comunicação - UnB

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[LEAK]<br />

build edges(C, P t ) = E<br />

find leak(C, P t ) = B<br />

dfs(sink, E) = B<br />

[SINK]<br />

sink → val(v) ∈ E<br />

dfs(sink, E) = B<br />

dfs(v, E) = B<br />

[VAL]<br />

val(v) → val(v ′ ) ∈ E<br />

dfs(v ′ , E) = B<br />

dfs(v, E) = B ∪ {val(v 1 ) → addr(v 2 )}<br />

[ADDR]<br />

val(v 1 ) → addr(v 2 ) ∈ E<br />

dfs(v, E) = {val(v 1 ) → addr(v 2 )}<br />

Figure 5. Recursive <strong>de</strong>finition of an address leak.<br />

The processing of load and store constraints is more complicated, because it<br />

<strong>de</strong>mands points-to information. We say that a variable v 1 points to a variable v 2<br />

if the value of v 1 holds the address of v 2 . The problem of conservatively estimating<br />

the points-to relations in a C-like program has been exhaustively studied in the<br />

compiler literature [An<strong>de</strong>rsen 1994, Har<strong>de</strong>kopf and Lin 2007, Pereira and Berlin 2009,<br />

Steensgaard 1996]. Therefore, we assume that we start the process of building the memory<br />

<strong>de</strong>pen<strong>de</strong>nce graph with a map P t ∶ V ↦ PowerSet(V ) that tells, for each variable<br />

v ∈ V , what is the subset of variables V ′ ⊆ V such that v points to every element v ′ ∈ V ′ .<br />

According to Rule STMEM, whenever we store a variable v 1 into the address pointed by<br />

variable v 0 , i.e., in the C jargon: *v0 = v1, then, for each variable v pointed by v 0 we<br />

create an edge from the value no<strong>de</strong> of v towards the value no<strong>de</strong> of v 0 . The ldmem constraint<br />

works in the opposite direction. Whenever we load the value stored in the address<br />

pointed by v 0 into a variable v 1 , i.e., v1 = *v0, then, for each variable v that might be<br />

pointed-to by v 0 we add an edge from the value no<strong>de</strong> of v 1 to the value no<strong>de</strong> of v.<br />

3.3. Traversing the Memory Depen<strong>de</strong>nce Graph to Find Address Leaks<br />

Figure 5 <strong>de</strong>fines a system of inference rules to characterize programs with address leaks.<br />

This <strong>de</strong>finition also gives a <strong>de</strong>clarative algorithm to find a path B in the memory <strong>de</strong>pen<strong>de</strong>nce<br />

graph <strong>de</strong>scribing the address leak. Rule LEAK tells us that a constraint system C,<br />

plus a set of points-to facts P t <strong>de</strong>scribes at least one address leak if the memory <strong>de</strong>pen<strong>de</strong>nce<br />

graph built from C and P t has a set of edges E, and E contains a path B, from<br />

sink to an address no<strong>de</strong>. To <strong>de</strong>note this last statement, we use the dfs predicate, which<br />

<strong>de</strong>scribes a <strong>de</strong>pth-first search along E, as one can readily infer from the Rules SINK, VAL<br />

and ADDR. These rules are self explanatory, and we will not <strong>de</strong>scribe them further.<br />

3.4. An Example of our Analysis in Action<br />

We illustrate the concepts introduced in this section via the C program shown in Figure 6.<br />

This program, although very artificial, contains the main elements that will allows us to<br />

231

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!