introduction and basics program analysis lecture...

47
1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter 2019/2020 Program Analysis – Lecture 1 Introduction and Basics Join the course on Ilias! See link on http://software-lab.org/teaching/winter2019/pa/

Upload: others

Post on 22-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

1

Prof. Dr. Michael Pradel

Software Lab, University of StuttgartWinter 2019/2020

Program Analysis – Lecture 1

Introduction and Basics

Join the course on Ilias! See link onhttp://software-lab.org/teaching/winter2019/pa/

Page 2: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

2

About Me: Michael Pradel

� Since 9/2019: Full Professorat University of Stuttgart

� Before� Studies at TU Dresden, ECP (Paris),

and EPFL (Lausanne)� PhD at ETH Zurich, Switzerland� Postdoctoral researcher at UC Berkeley, USA� Assistant Professor at TU Darmstadt� Sabbatical at Facebook, Menlo Park, USA

Page 3: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

3

About the Software Lab

� My research group since 2014� Focus: Tools and techniques for

building reliable, efficient, and securesoftware� Program testing and analysis� Machine learning, security

� Thesis and job opportunities

Page 4: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

4

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course project� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, etc.

Page 5: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

5

Program Testing & Analysis

What you probably know:

� Manual testing or semi-automatedtesting:JUnit, Selenium, etc.

� Manual ”analysis” of programs:Code inspection, debugging, etc.

Focus of this course:Automated testing and program analysis

Page 6: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

6 - 1

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

Page 7: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

6 - 2

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

0.5-25/KLoCin deliveredsoftware

Page 8: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

6 - 3

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

1.5 years tofind a bug[Palix2011]

Page 9: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

6 - 4

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

Ariane 5 Northeastblackout

Therac-25

Page 10: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

7 - 1

What is Program Analysis?

� Automated analysis of programbehavior, e.g., to� find programming errors� optimize performance� find security vulnerabilities

ProgramInput Output

Page 11: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

7 - 2

What is Program Analysis?

� Automated analysis of programbehavior, e.g., to� find programming errors� optimize performance� find security vulnerabilities

Program

Additional information

Input Output

Page 12: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

7 - 3

What is Program Analysis?

� Automated analysis of programbehavior, e.g., to� find programming errors� optimize performance� find security vulnerabilities

Program

Additional information

InputInput

InputOutputOutput

Output

Page 13: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

8 - 1

Static vs. Dynamic Analysis

Static Dynamic

� Analyse source code,byte code, or binary

� Typically:� Consider all inputs� Overapproximate

possible behavior

� Analyze programexecution

� Typically:� Consider current

input� Underapproximate

possible behavior

Page 14: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

8 - 2

Static vs. Dynamic Analysis

Static Dynamic

� Analyse source code,byte code, or binary

� Typically:� Consider all inputs� Overapproximate

possible behavior

� Analyze programexecution

� Typically:� Consider current

input� Underapproximate

possible behavior

E.g., compilers,lint-like tools

E.g., automatedtesting, profilers

Page 15: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

9 - 1

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Quiz: What are the possible outputs?

https://ilias3.uni-stuttgart.de/vote/KN2I

Page 16: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

9 - 2

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Overapproximation: ”yes”, ”no”, ”maybe”� Consider all paths (that are feasible based on

limited knowledge)

Page 17: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

9 - 3

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Underapproximation: ”yes”� Execute the program once

Page 18: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

9 - 4

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Sound and complete: ”yes”, ”no”� For this example: Can explore both feasible paths

Page 19: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

10 - 1

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Page 20: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

10 - 2

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Overapproximation: Any value� Consider all paths (that are feasible based on

limited knowledge about random())

Page 21: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

10 - 3

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Underapproximation:Some number in [0,2), e.g., 1.234� Execute the program once

Page 22: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

10 - 4

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Sound and complete?� Exploring all possible outputs:

Practically impossible� This is the case for most real-world programs

Page 23: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

7

Page 24: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

12

Test Generation

� Dynamic analysis:Requires input to run the program

� Test generation:Creates inputs automatically

� Examples� Generate JUnit tests:

Input = sequence of method calls� UI-level test generation:

Input = sequence UI events� Fuzz-test a compiler: Input = program

Page 25: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

13

How Does All This Help Me?

Improve the quality of your code� Fewer bugs� Better performance� More secure software

Save time during manual testing

Become a better developer� Get better understanding of program’s behavior� Avoid common pitfalls� Learn to use and write tools

Page 26: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

14

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course project� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, etc.

Page 27: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

15

Organization

� Two lecture slots per week

� But not all used: See course page

� Weekly reading material

� Throughout the semester:Course project

� December 17: Mid-term exam

� End of semester: Final exam

Page 28: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

16

Grading

� Two lecture slots per week

� But not all used: See course page

� Weekly reading material

� Throughout the semester:Course project

� December 17: Mid-term exam

� End of semester: Final exam 50%

40%

10%

Page 29: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

17 - 1

A Friendly Warning

� Read regularly (otherwise, you won’t be able tocatch up)

� Work regularly on the course project

This is not going to bean easy course!

Page 30: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

17 - 2

A Friendly Warning

� Read regularly (otherwise, you won’t be able tocatch up)

� Work regularly on the course project

This is not going to bean easy course!

... but the effort is worth it!

Page 31: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

18

Programming Language

Most concepts taught in this course:Language-independent

Most examples: JavaScript� Very popular: client-side web applications, but

also for server, mobile, and desktop applications� Various interesting research challenges

Course project: Java and JavaScript� Analysis written in Java� Analysis of JavaScript code

Page 32: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

19

Ilias

Platform for discussions, in-classquizzes, and sharing additional material

� Please register for the course� Use it for all questions related to the course� Messages sent to all students go via Ilias

Link to Ilias course onsoftware-lab.org/teaching/winter2019/pa/

Page 33: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

20

Learning Material

There is no script or single book thatcovers everything

� Slides and hand-written nodes:Available after lecture

� Pointers to papers, book chapters, and webresources

Page 34: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

21

Course Project

� Design, implement, and evaluate aprogram analysis based on an existingframework

� Data flow analysis of JavaScript code

� Based on Google Closure compiler

� Individual, independent project

� Mentor available for questions

Page 35: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

22

Course Project: Timeline

� Project published on November 4

� Due on February 7

� Implementation and results

� Report

� Week of February 10 to 14

� Presentation of projects

Page 36: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

23

Academic Integrity

� Work you submit must be your own

� Unauthorized group efforts and anyform of plagiarism are consideredacademic dishonesty and will bepunished

� Allowed to discuss the problem withyour peers, but not to reuse any partof an existing solution

Page 37: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

24 - 1

Exams

Mid-term exam (written)� Recommended but not mandatory� 10% of final grade, but mostly to help you learn� On Dec 17 in the lecture slot

Final exam (written)� End of semester

Page 38: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

24 - 2

Exams

Mid-term exam (written)� Recommended but not mandatory� 10% of final grade, but mostly to help you learn� On Dec 17 in the lecture slot

Final exam (written)� End of semester

For both: Open book exam� Bring books, papers, etc.� No electronic devices� Will test your understanding, not your memory!

Page 39: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

25

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course projects� Term paper� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, CGs, PDGs, etc.

Page 40: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

8

Page 41: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

9

Page 42: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

10

Page 43: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

11

Page 44: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

12

Page 45: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

13

Page 46: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

14

Page 47: Introduction and Basics Program Analysis Lecture 1software-lab.org/teaching/winter2019/pa/lecture_introduction_.pdf · Introduction and Basics Join the course on Ilias! See link on

27

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course project� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, etc. 4