• No results found

State of the World - Statically Verifying API Usage Rule

N/A
N/A
Protected

Academic year: 2021

Share "State of the World - Statically Verifying API Usage Rule"

Copied!
26
0
0

Loading.... (view fulltext now)

Full text

(1)

Statically Verifying API Usage Rule using Tracematches

Xavier Noumbissi, Patrick Lam University of Waterloo

(2)

Outline 1 Problem 2 Constraint language 3 Example 4 Analysis Overview 5 Related Work 6 Future Work 7 Conclusion

(3)

Problem

Software relies on Libraries

APPLICATION

LIBRARY1

(4)

Problem Abstraction Layer Plug-in / Wrapper-Library APPLICATION PLUGIN 1 PLUGIN 2 LIBRARY 1 LIBRARY2

(5)

Problem Expressing Properties Verification Properties

Two types of properties:

State Properties: Pre- and Post-Conditions Temporal Properties: Typestates, LTL, etc.

(6)

Constraint language Tracematches

Tracematches: Unauthorized events sequence

Example: Do not write to a file after closing it.

Regular Expression: open write* close+ write

q0

start q1 q2 q3

open

write close

close write

(7)

Example Configuration Example

(8)

Example The Code Application & Plug-in

p u b l i c c l a s s BookHandler { F i l e W r i t e r l 1 ; p u b l i c v o i d openBook ( S t r i n g b ){ l 1 = new F i l e W r i t e r ( b ) ; } p u b l i c v o i d p r i n t C h a p t e r ( S t r i n g s ){ l 1 . w r i t e ( s ) ; } p u b l i c v o i d p r i n t S e c t i o n ( S t r i n g s ){ i f ( n u l l == s ) l 1 . f l u s h ( ) ; e l s e l 1 . w r i t e ( s ) ; } p u b l i c v o i d addIndex ( S t r i n g [ ] t ){ f o r ( i n t k = 0 ; k<t . l e n g t h ; ++k ) { l 1 . w r i t e ( t [ k ] ) ; } F i l e W r i t e r l 3 = l 1 ; / / I l l u s t r a t e s l 3 . c l o s e ( ) ; / / a l i a s i n g } p u b l i c v o i d c l o s e ( ){ l 1 . f l u s h ( ) ; l 1 . c l o s e ( ) ; } } p u b l i c c l a s s B o o k E d i t o r { p u b l i c s t a t i c v o i d main ( S t r i n g [ ] args ){

BookHandler b = new BookHandler ( ) ; S t r i n g [ ] i n d e x = {"book", "chapter"}; S t r i n g B u i l d e r s t r = new S t r i n g B u i l d e r ( ) ; b . openBook ("book.txt") ;

b . p r i n t C h a p t e r ("A chapter") ; s t r . append ("Not in abstract CFG") ; b . p r i n t S e c t i o n ("A section") ; b . addIndex ( i n d e x ) ; b . c l o s e ( ) ; } } ACFG

(9)

Example Usage Rule

A Usage Rule for java.io.FileWriter

Nowriteorflushon aFileWriterafter aclose.

q0 start q1 q2 write,flush close close write,flush

(10)

Example A Rule Violation A Violation of the Rule

The developer expects:

close: closes the book’s stream

addIndex: does not close the book’s stream

But:

addIndex: closes the stream

close: flushes the stream before closing it

(11)

Example Plug-in summary Method summaries Summary ofBookHandler.addIndex if (k < t.length) k = 0 l1.write(t[k]); ++k; FileWriter l3=l1; l3.close(); T F q0 q2 q1 l1.close() l1.write()

(12)

Example Plug-in summary Plug-in summary

Reusable as long as Plug-in code unchanged Represents all events sequences on

FileWriter objects

Storage of summaries improves scalability

(13)

Example Application code Abstracted CFG for BookEditor.main

The code

Here’s a CFG which only includes the

BookHandlercalls. Statements on edges q0 q1 q2 q3 q4 q6 b.openBook(...) b.printChapter(...) b.printSection(...) b.addIndex(...) b.closeBook(...)

(14)

Example Application code Edge Substitution - 1

Substitute method-call edges with NFA summaries:

Summarizes application behavior with respect to tracematch events

May-alias information at interprocedural level Unless FileWriter objects may not alias

(15)

Example Application code Edge Substitution - 2 c0 c1 c2 c3 c4 c5 c6 c7 c8 l1.write() l1.write() l1.flush() l1.write() l1.close() l1.flush() l1.close()

(16)

Example Application code Tracematch: Runtime Monitor (RM)

Combined execution of application and RM:

Synchronous Product Automaton (SPA): defines a

transition for an event only if it occurs in both automatons

Shared actions: tracematch events

(17)

Example Application code Synchronous Product Automaton - 1

c0q0 c1q0 c3q0 c2q0 c4q0 c5q1 c6q2 c8q0 l1.write() l1.flush() l1.write() l1.close() l1.write() l1.flush()

(18)

Example Application code Synchronous Product Automaton - 2

c0q0 c1q0 c3q0 c2q0 c4q0 c5q1 c6q2 c8q0 l1.write() l1.flush() l1.write() l1.close() l1.write() l1.flush()

An accepting path represents a violation of the rules.

(19)

Analysis Overview Overview Our approach: Four Phases

1 Compute plug-in summaries (Preliminary phase)

2 Generate application Abstract CFGs

3 Integrate plug-in summaries to abstract CFGs

(20)

Analysis Overview Overview Implementation

Uses the Soot Framework

Interaction of inter- and intra-procedural analysis Intraprocedural analysis as a region-based

analysis

(21)

Analysis Overview Overview Computing Plug-in Summaries

Advantages of storing summaries:

Effects of whole program analysis with partial code

No need to have plug-in code

Manual creation of plug-in summary Plug-in summary as a contract

(22)

Analysis Overview Overview Library Object Accesses

Library objects may be accessible as:

Member variables

Local instantiated variables Others: out of scope

(23)

Related Work

Related Work

Static optimization of runtime monitors: static verification

of tracematches at the intraprocedural level (Bodden et al.)

Analysis of multiple interactive objects: Uses

tracematches to verify correct interaction of several objects (Naeem et al.)

Component Level data-flow Analysis (CLA): computes

summaries and properties of software with partial

information (source code or summaries) of its components. (Rountev et al.)

(24)

Future Work

Future Work

Complete implementation

Test analysis on production software

Use of constraint-solvers to remove false positives from summaries

Try to improve scalability of other analyses on tracematches using summaries

(25)

Conclusion

Contributions

Check that abstraction layers do not introduce bugs

Use of summaries as contracts

Use of summaries for other analyses on tracematches

(26)

Conclusion

THANK YOU !

Comments & Questions

References

Related documents

Swithun Crowe (University of St Andrews) Digital archiving and file validation June 1, 2012 2 /

In response to Harry’s final actions in Deathly Hallows, Harry’s journey towards moral maturity culminates far beyond that of a normal 17-year-old adolescent, and through

2) Social Entrepreneurship and Improved Educational Management Program at the Pedro Aguirre Cerda state school (LIPAC) in Cauquenes, organised by Glencore- Xstrata (year 1),

The framework designed here is constructivist in the following ways: it is learner-centred (he is involved in the learning process, has a certain degree of control

“THAT the Board approves the 2013/2014 Meeting Labour Market Needs Monitoring Report (Policy A-40) based on reasonable interpretations of Board policy and evidence

5.1 It is essential that personnel involved in the work of geotechnical investigation and report should have appropriate specialized knowledge and experience. 5.2 Field work shall

The Big Picture – Continuous Delivery Platform Business Decision To Go Live All Humans are on the Same Side Build Config Deploy Test Systems- Automation Scale Out Data Centers...

Vitality Shared-Value Insurance reinforced the strong value proposition, offering Vitality members rewards