• Keine Ergebnisse gefunden

Qualit¨atssicherung in der Softwareentwicklung VU 9 DI Dr. Bernhard K. Aichernig

N/A
N/A
Protected

Academic year: 2021

Aktie "Qualit¨atssicherung in der Softwareentwicklung VU 9 DI Dr. Bernhard K. Aichernig"

Copied!
44
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Concolic Execution

Qualit¨ atssicherung in der Softwareentwicklung

VU 9

DI Dr. Bernhard K. Aichernig

Institut f¨ur Softwaretechnologie (IST) TU Graz

Sommersemester 2012

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(2)

1

Symbolic Execution

2

Concolic Execution

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(3)

Concolic Execution

Literatur: Symbolic Execution

James C. King. Symbolic Execution and Program Testing, Communications of the ACM, Volume 19, Issue 7. July 1976, Pages 385–394.

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(4)

Instead of normal program inputs

one supplies symbols representing arbitrary values.

Execution proceeds like normal execution,

except that values may be symbolic formulas over the input values.

Interesting: symbolic execution of branching statements (e.g.

if-statements)

A technique between testing and formal proofs.

Testing: execution with some concrete input values Proofs: no execution

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(5)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c ) 2 {

3 i n t x , y , z ; 4 x = a + b ; 5 y = b + c ; 6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(6)

1 i n t sum ( i n t a , i n t b , i n t c ) ← a = α

a

, b = α

b

, c = α

c

2 {

3 i n t x , y , z ; 4 x = a + b ; 5 y = b + c ; 6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(7)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c ) ← a = α

a

, b = α

b

, c = α

c

2 {

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; 5 y = b + c ; 6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(8)

1 i n t sum ( i n t a , i n t b , i n t c ) ← a = α

a

, b = α

b

, c = α

c

2 {

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = α

a

+ α

b

, y = 0, z = 0 5 y = b + c ;

6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(9)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c ) ← a = α

a

, b = α

b

, c = α

c

2 {

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = α

a

+ α

b

, y = 0, z = 0 5 y = b + c ; ← x = α

a

+ α

b

, y = α

b

+ α

c

, z = 0 6 z = x + y − b ;

7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(10)

1 i n t sum ( i n t a , i n t b , i n t c ) ← a = α

a

, b = α

b

, c = α

c

2 {

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = α

a

+ α

b

, y = 0, z = 0 5 y = b + c ; ← x = α

a

+ α

b

, y = α

b

+ α

c

, z = 0

6 z = x + y − b ; ← x = α

a

+ α

b

, y = α

b

+ α

c

, z = α

a

+ α

b

+ α

c

7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(11)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c ) ← a = α

a

, b = α

b

, c = α

c

2 {

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = α

a

+ α

b

, y = 0, z = 0 5 y = b + c ; ← x = α

a

+ α

b

, y = α

b

+ α

c

, z = 0

6 z = x + y − b ; ← x = α

a

+ α

b

, y = α

b

+ α

c

, z = α

a

+ α

b

+ α

c

7 r e t u r n z ; return α

a

+ α

b

+ α

c

8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(12)

1 i n t min ( i n t x , i n t y ) 2 {

3 i n t z ;

4 i f ( x<y )

5 z=x ;

6 e l s e

7 z=y ;

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(13)

Concolic Execution

Path Condition

Symbolic execution of if-statement requires path condition (pc).

pc is a Boolean expression over symbolic inputs.

pc never contains program variables!

pc is a conjunction of branching conditions.

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(14)

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ;

4 i f ( x<y )

5 z=x ;

6 e l s e

7 z=y ;

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(15)

Concolic Execution

Bsp. Min

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ; ← x = α

x

, y = α

y

, z = 0, pc = true 4 i f ( x<y )

5 z=x ;

6 e l s e

7 z=y ;

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(16)

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ; ← x = α

x

, y = α

y

, z = 0, pc = true

4 i f ( x<y ) ← Case 1: x = α

x

, y = α

y

, z = 0, pc = α

x

< α

y

5 z=x ;

6 e l s e

7 z=y ;

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(17)

Concolic Execution

Bsp. Min

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ; ← x = α

x

, y = α

y

, z = 0, pc = true

4 i f ( x<y ) ← Case 1: x = α

x

, y = α

y

, z = 0, pc = α

x

< α

y

5 z=x ; ← x = α

x

, y = α

y

, z = α

x

, pc = α

x

< α

y

6 e l s e

7 z=y ;

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(18)

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ; ← x = α

x

, y = α

y

, z = 0, pc = true

4 i f ( x<y ) ← Case 1: x = α

x

, y = α

y

, z = 0, pc = α

x

< α

y

5 z=x ; ← x = α

x

, y = α

y

, z = α

x

, pc = α

x

< α

y

6 e l s e ← Case 2: x = α

x

, y = α

y

, z = 0, pc = ¬α

x

< α

y

7 z=y ;

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(19)

Concolic Execution

Bsp. Min

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ; ← x = α

x

, y = α

y

, z = 0, pc = true

4 i f ( x<y ) ← Case 1: x = α

x

, y = α

y

, z = 0, pc = α

x

< α

y

5 z=x ; ← x = α

x

, y = α

y

, z = α

x

, pc = α

x

< α

y

6 e l s e ← Case 2: x = α

x

, y = α

y

, z = 0, pc = ¬α

x

< α

y

7 z=y ; ← x = α

x

, y = α

y

, z = α

y

, pc = ¬α

x

< α

y

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(20)

1 i n t min ( i n t x , i n t y ) ← x = α

x

, y = α

y

, pc = true 2 {

3 i n t z ; ← x = α

x

, y = α

y

, z = 0, pc = true

4 i f ( x<y ) ← Case 1: x = α

x

, y = α

y

, z = 0, pc = α

x

< α

y

5 z=x ; ← x = α

x

, y = α

y

, z = α

x

, pc = α

x

< α

y

6 e l s e ← Case 2: x = α

x

, y = α

y

, z = 0, pc = ¬α

x

< α

y

7 z=y ; ← x = α

x

, y = α

y

, z = α

y

, pc = ¬α

x

< α

y

8 r e t u r n z ; ← return(z = α

x

∧ α

x

< α

y

) ∨ (z = α

y

∧ ¬α

x

< α

y

) 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(21)

Concolic Execution

Bsp. Min(a,b,c)

1 i n t min ( i n t a , i n t b , i n t c ) 2 {

3 r e t u r n

4 min (

5 min ( a , b ) ,

6 c

7 ) ;

8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(22)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) ,

6 c

7 ) ;

8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(23)

Concolic Execution

Bsp. Min(a,b,c)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) , ← (= α

a

∧ pc = α

a

< α

b

) ∨ (= α

b

∧ pc = α

a

≥ α

b

)

6 c

7 ) ;

8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(24)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) , ← (= α

a

∧ pc = α

a

< α

b

) ∨ (= α

b

∧ pc = α

a

≥ α

b

)

6 c ← c = α

c

7 ) ;

8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(25)

Concolic Execution

Bsp. Min(a,b,c)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) , ← (= α

a

∧ α

a

< α

b

) ∨ (= α

b

∧ α

a

≥ α

b

)

6 c ← c = α

c

7 ) ; ← (= α

a

∧ pc = α

a

< α

b

∧ α

a

< α

c

) 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(26)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) , ← (= α

a

∧ α

a

< α

b

) ∨ (= α

b

∧ α

a

≥ α

b

)

6 c ← c = α

c

7 ) ; ← (= α

a

∧ pc = α

a

< α

b

∧ α

a

< α

c

) ∨ 8 } (= α

b

∧ pc = α

a

≥ α

b

∧ α

b

< α

c

)

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(27)

Concolic Execution

Bsp. Min(a,b,c)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) , ← (= α

a

∧ α

a

< α

b

) ∨ (= α

b

∧ α

a

≥ α

b

)

6 c ← c = α

c

7 ) ; ← (= α

a

∧ pc = α

a

< α

b

∧ α

a

< α

c

) ∨ 8 } (= α

b

∧ pc = α

a

≥ α

b

∧ α

b

< α

c

) ∨ 9 (= α

c

∧ pc = α

a

< α

b

∧ α

a

≥ α

c

)

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(28)

1 i n t min ( i n t a , i n t b , i n t c )

2 { ← a = α

a

, b = α

b

, c = α

c

, pc = true 3 r e t u r n

4 min (

5 min ( a , b ) , ← (= α

a

∧ α

a

< α

b

) ∨ (= α

b

∧ α

a

≥ α

b

)

6 c ← c = α

c

7 ) ; ← (= α

a

∧ pc = α

a

< α

b

∧ α

a

< α

c

) ∨ 8 } (= α

b

∧ pc = α

a

≥ α

b

∧ α

b

< α

c

) ∨ 9 (= α

c

∧ pc = α

a

< α

b

∧ α

a

≥ α

c

) ∨

10 (= α

c

∧ pc = α

a

≥ α

b

∧ α

b

≥ α

c

)

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(29)

Concolic Execution

Symbolic Execution Tree

Symbolic execution forcs at each if-statement:

α

a

< α

b

α

a

< α

c

min = α

a

T

min = α

c

F T

α

b

< α

c

min = α

b

T

min = α

c

F F

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(30)

Calculation: pc

2

= true ∧ α

a

< α

b

∧ ¬(α

a

< α

c

)

Path condition represents equivalence class for all concrete values taking a path.

Concrete test cases: find concrete values satisifying pc e.g. for pc

2

: a = 0, b = 1, c = 0

Result: path coverage

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(31)

Concolic Execution

Limitations

infinite number of paths (loops) infeasible paths (pc = false )

limitations of solvers and theorem provers all code must be accessible (white-box) only for single-threaded programs

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(32)

Concolic = Concrete + Symbolic

also called Dynamic Symbolic Execution (Microsoft) Concrete and Symbolic Execution in parallel

Due to concrete execution:

No infeasable paths!

Integration of black-box components possible.

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(33)

Concolic Execution

Concolic Execution Loop

Algorithm

1

Covered := {} covered set of inputs

2

select new input i 6∈ Covered stop if no one found

3

execute Program(i ) and record path condition C C(i) holds

4

Covered := Covered ∪ {i|C (i )}

5

goto 2

New input i 6∈ Covered after n iterations:

solve ¬C

i1

∧ · · · ∧ ¬C

in

Stop when ¬C

i1

∧ · · · ∧ ¬C

in

= false

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(34)

1 i n t sum ( i n t a , i n t b , i n t c ) 2 {

3 i n t x , y , z ; 4 x = a + b ; 5 y = b + c ; 6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(35)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c )

2 { ← a = (α

a

, 1), b = (α

b

, 2), c = (α

c

, 3) 3 i n t x , y , z ;

4 x = a + b ; 5 y = b + c ; 6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(36)

1 i n t sum ( i n t a , i n t b , i n t c )

2 { ← a = (α

a

, 1), b = (α

b

, 2), c = (α

c

, 3)

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; 5 y = b + c ; 6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(37)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c )

2 { ← a = (α

a

, 1), b = (α

b

, 2), c = (α

c

, 3)

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = (α

a

+ α

b

, 3), y = (0, 0), z = (0, 0) 5 y = b + c ;

6 z = x + y − b ; 7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(38)

1 i n t sum ( i n t a , i n t b , i n t c )

2 { ← a = (α

a

, 1), b = (α

b

, 2), c = (α

c

, 3)

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = (α

a

+ α

b

, 3), y = (0, 0), z = (0, 0) 5 y = b + c ; ← x = (α

a

+ α

b

, 3), y = (α

b

+ α

c

, 5), z = (0, 0) 6 z = x + y − b ;

7 r e t u r n z ; 8 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(39)

Concolic Execution

Bsp. Sum

1 i n t sum ( i n t a , i n t b , i n t c )

2 { ← a = (α

a

, 1), b = (α

b

, 2), c = (α

c

, 3)

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = (α

a

+ α

b

, 3), y = (0, 0), z = (0, 0) 5 y = b + c ; ← x = (α

a

+ α

b

, 3), y = (α

b

+ α

c

, 5), z = (0, 0) 6 z = x + y − b ; ← x = (α

a

+ α

b

, 3), y = (α

b

+ α

c

, 5),

7 z = (α

a

+ α

b

+ α

c

, 6)

8 r e t u r n z ; 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(40)

1 i n t sum ( i n t a , i n t b , i n t c )

2 { ← a = (α

a

, 1), b = (α

b

, 2), c = (α

c

, 3)

3 i n t x , y , z ; ← x = 0, y = 0, z = 0

4 x = a + b ; ← x = (α

a

+ α

b

, 3), y = (0, 0), z = (0, 0) 5 y = b + c ; ← x = (α

a

+ α

b

, 3), y = (α

b

+ α

c

, 5), z = (0, 0) 6 z = x + y − b ; ← x = (α

a

+ α

b

, 3), y = (α

b

+ α

c

, 5),

7 z = (α

a

+ α

b

+ α

c

, 6)

8 r e t u r n z ; ← return(α

a

+ α

b

+ α

c

, 6) 9 }

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(41)

Concolic Execution

Bsp. Min

1 i n t min ( i n t x , i n t y ) ← x = (α

x

, 0), y = (α

y

, 0), pc = true 2 {

3 i n t z ; ← x = (α

x

, 0), y = (α

y

, 0), z = (0, 0), pc = true 4 i f ( x<y ) ¬(0 < 0)

5 z=x ;

6 e l s e ← x = (α

x

, 0), y = (α

y

, 0), z = (0, 0), pc = ¬(α

x

< α

y

) 7 z=y ; ← x = (α

x

, 0), y = (α

y

, 0), z = (α

y

, 0), pc = ¬(α

x

< α

y

) 8 r e t u r n z ; ← return z = (α

y

, 0), pc = ¬(α

x

< α

y

)

9 }

Find new input values such that α

x

< α

y

and execute again, e.g.

min(0, 1)

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(42)

1 i n t min ( i n t x , i n t y ) ← x = (α

x

, 0), y = (α

y

, 0), pc = true 2 {

3 i n t z ; ← x = (α

x

, 0), y = (α

y

, 0), z = (0, 0), pc = true 4 i f ( x<y ) ¬(0 < 0)

5 z=x ;

6 e l s e ← x = (α

x

, 0), y = (α

y

, 0), z = (0, 0), pc = ¬(α

x

< α

y

) 7 z=y ; ← x = (α

x

, 0), y = (α

y

, 0), z = (α

y

, 0), pc = ¬(α

x

< α

y

) 8 r e t u r n z ; ← return z = (α

y

, 0), pc = ¬(α

x

< α

y

)

9 }

Find new input values such that α

x

< α

y

and execute again, e.g.

min(0, 1)

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(43)

Concolic Execution

Limitations

infinite number of paths: upper bounds limitations of solvers and theorem provers for single-threaded programs

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

(44)

Cute, jCute Pex (Microsoft)

PathCrawler (see exercise)

DI Dr. Bernhard K. Aichernig Qualit¨atssicherung in der Softwareentwicklung

Referenzen

ÄHNLICHE DOKUMENTE

The contributions are: (1) A new cost representation (cost structure) that can represent complex polynomial upper and lower bounds (Sec. 3); and (2) techniques to infer cost

We shall exploit parametric stability and sensitivity results, ideas of multi- objective optimization and the contamination technique to derive bounds for the perturbed optimal

Two Case Studies of Open Source Software Development: Apache and Mozilla, ACM Transactions on Software Engineering and Methodology, Vol. Why Open Source Software / Free

Unterst¨ utzt nur bedingt verschachtelte Quantoren Unterst¨ utzt keine Interface-Spezifikation mit Modell-Variablen. Probleme

ation of imperative programs and tail reursive funtions, whih onsists of the.

This paper provides new results on: the computation of the Nakamura number, lower and upper bounds for it or the maximum achievable Nakamura number for subclasses of simple games

Spence, The maximum size of a partial 3-spread in a finite vector space over GF (2), Designs, Codes and Cryptography 54 (2010), no.. Storme, Galois geometries and coding

Besides the geometric interest in maximum partial k-spreads, they also can be seen as a special case of q sub- space codes in (network) coding theory.. Here the codewords are