Preventing bugs with pluggable type checking Michael D. Ernst University of Washington Object x)

Slides:



Advertisements
Similar presentations
Static Analysis for Security
Advertisements

Designing a Program & the Java Programming Language
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
Introduction to Maven 2.0 An open source build tool for Enterprise Java projects Mahen Goonewardene.
Identity and Equality Based on material by Michael Ernst, University of Washington.
Type-based Taint Analysis for Java Web Applications Wei Huang, Yao Dong and Ana Milanova Rensselaer Polytechnic Institute 1.
Object and Reference Immutability using Java Generics Yoav Zibin, Alex Potanin(*), Mahmood Ali, Shay Artzi, Adam Kiezun, and Michael D. Ernst MIT Computer.
GUI Threading Explained and Verified Michael Ernst U. of Washington, Seattle, USA IMDEA Software Institute, Madrid, Spain joint work with Colin Gordon,
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
Java Annotations. Annotations  Annotations are metadata or data about data. An annotation indicates that the declared element should be processed in.
Static code check – Klocwork
Detecting and preventing bugs with pluggable type-checking Michael D. Ernst University of Washington Joint work with Mahmood Ali, Werner Dietl, …
Visualizing Type Qualifier Inference with Eclipse David Greenfieldboyce Jeffrey S. Foster University of Maryland.
JArchitect Benefits by CoderGears
CQual: A Tool for Adding Type Qualifiers to C Jeff Foster et al UC Berkeley OSQ Retreat, May
Javari: Adding Reference Immutability to Java Matthew Tschantz and Michael Ernst MIT CSAIL.
Usable code verification: balancing costs and benefits Two nuggets: User-defined verifiers Crowd-sourced verification Michael D. Ernst University of Washington.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
What’s new in Stack 3.2 Michael Youngstrom. Disclaimer This IS a presentation – So sit back and relax Please ask questions.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Object x) { List lst; … } Detecting and preventing null pointer errors with pluggable type-checking CSE 331 University of Washington.
CSC-682 Cryptography & Computer Security Sound and Precise Analysis of Web Applications for Injection Vulnerabilities Pompi Rotaru Based on an article.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Preventing bugs with pluggable type checking Michael Ernst and Mahmood Ali University of Washington and MIT OOPSLA 2009 tutorial Object.
P.R. James © P.Chalin et al.1 An Integrated Verification Environment for JML: Architecture and Early Results Patrice Chalin, Perry R. James, and George.
Axel Naumann. Outline  Static Code Analysis  Coverity  Reporting Tools, Report Quality  "Demo": Examples Axel Naumann Application Area Meeting2.
User-defined type checkers for error detection and prevention in Java Michael D. Ernst MIT Computer Science & AI Lab
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
1 XINS features 101 new features of XINS This presentation has 102 pages.
PwC New Technologies New Risks. PricewaterhouseCoopers Technology and Security Evolution Mainframe Technology –Single host –Limited Trusted users Security.
1© Nokia Siemens Networks Presentation / Author / Date For internal use T Better Code Faster - Next Generation Java Continuous Integration Environment.
Demo of Scalable Pluggable Types Michael Ernst MIT Dagstuhl Seminar “Scalable Program Analysis” April 17, 2008.
How analysis can hinder source code manipulaton And what to do about it Michael Ernst University of Washington.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
JSR 308: Type Annotations Making Java annotations more general and more useful Spec leads: Michael Ernst & Alex Buckley Implementation lead: Werner Dietl.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Java Annotations. Annotations  Annotations are metadata or data about data. An annotation indicates that the declared element should be processed in.
1 CSE 331 Hash codes; annotations slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Java Annotations for Types and Expressions Mathias Ricken October 24, 2008 COMP 617 Seminar.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Detecting and preventing bugs with pluggable type-checking Michael D. Ernst University of Washington Joint work with Werner Dietl, and many others
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
ReIm & ReImInfer: Checking and Inference of Reference Immutability and Method Purity Wei Huang 1, Ana Milanova 1, Werner Dietl 2, Michael D. Ernst 2 1.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Preventing bugs with pluggable type checking Michael Ernst University of Washington Joint work with Mahmood Ali and Matthew Papi Object.
Preventing bugs with pluggable type-checking Michael Ernst MIT
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 16 Checker Framework.
CSE 332: C++ templates and generic programming II Review: Concepts and Models Templates impose requirements on type parameters –Types that are plugged.
Findbugs Tin Bui-Huy September, Content What is bug? What is bug? What is Findbugs? What is Findbugs? How to use Findbugs? How to use Findbugs?
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Jeremy Nimmer, page 1 Automatic Generation of Program Specifications Jeremy Nimmer MIT Lab for Computer Science Joint work with.
CSE 331 Software Design and Implementation
Content Coverity Static Analysis Use cases of Coverity Examples
Javarifier: inference of reference immutability
Logger, Assert and Invariants
Lightweight Verification of Array Indexing
Introduction to C# AKEEL AHMED.
CodePeer Update Arnaud Charlet CodePeer Update Arnaud Charlet
CodePeer Update Arnaud Charlet CodePeer Update Arnaud Charlet
Java Programming Course
Introduction to Static Analyzer
CSE 331 Annotations slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
(Computer fundamental Lab)
Semantic Type Qualifiers
Java Annotations for Invariant Specification
Presentation transcript:

Preventing bugs with pluggable type checking Michael D. Ernst University of Washington Object x) { List lst; … }

Motivation java.lang.NullPointerException

Java’s type checking is too weak Type checking prevents many bugs int i = “hello”; // type error Type checking doesn’t prevent enough bugs System.console().readLine();  NullPointerException Collections.emptyList().add(“One”);  UnsupportedOperationException

Some errors are silent Date date = new Date(0); myMap.put(date, “Java Epoch”); date.setYear(70); myMap.put(date, “Linux Epoch”);  Corrupted map dbStatement.executeQuery(userInput);  SQL injection attack Initialization, data formatting, equality tests, …

Solution: Pluggable type systems Design a type system to solve a specific problem Write type qualifiers in code (or, type Date date = new Date(0); date.setTime(70); // compile-time error Type checker warns about violations (bugs) % javac -processor NullnessChecker MyFile.java MyFile.java:149: dereference of possibly-null reference bb2 allVars = bb2.vars; ^

Benefits of pluggable types Improve documentation Find bugs in programs Guarantee the absence of errors Aid compilers, optimizers, and analysis tools Reduce number of assertions and run-time checks Possible negatives: – Must write the types (or use type inference) – False positives are possible (can be suppressed)

Sample checkers Null dereferences Mutation and side-effects Equality tests Locking Security: encryption, tainting, access control Aliasing Strings: localization, regex syntax,... Typestate (e.g., open/closed files) You can write your own!

Using checkers Designed as compiler plug-ins (i.e., annotation processors) Use familiar error messages % javac –processor NullnessChecker MyFile.java MyFile.java:9: incompatible types. nonNullVar = nullableValue; ^ found String String

Demos available! Catch me anytime today or tomorrow

Checkers are effective Scales to > 200,000 LOC Each checker found errors in each code base it ran on – Verified by a human and fixed

Comparison: other Nullness tools Null pointer errorsFalse warnings Annotations written FoundMissed Checker Framework FindBugs081 0 Jlint088 0 PMD080 0 Checking the Lookup program for file system searching (4KLOC) Distributed with Daikon (>100KLOC verified by our checker) False warnings are suppressed via an annotation or assertion

Checkers are featureful Full type systems: inheritance, overriding, etc. Generics (type polymorphism) – Also qualifier polymorphism Flow-sensitive type qualifier inference Qualifier defaults Warning suppression

Checkers are usable Integrated with toolchain – javac, Ant, Maven, Eclipse, Netbeans Few false positives Annotations are not too verbose : 1 per 75 lines with program-wide defaults, 1 per 2000 liness : 124 annotations in 220KLOC revealed 11 bugs – Possible to annotate part of program – Fewer annotations in new code Inference tools: nullness, mutability

What a checker guarantees The program satisfies the type property. There are: – no bugs (of particular varieties) – no wrong annotations Caveat 1: only for code that is checked – Native methods – Reflection – Code compiled without the pluggable type checker – Suppressed warnings Indicates what code a human should analyze – Checking part of a program is still useful Caveat 2: The checker itself might contain an error

Annotating libraries Each checker comes with JDK annotations – Typically, only for signatures, not bodies – Finds errors in clients, but not in the library itself Inference tools for annotating new libraries

SQL injection attack Server code bug: SQL query constructed using unfiltered user input query = “SELECT * FROM users ” + “WHERE name=‘” + userInput + “’;”; User inputs: a’ or ‘t’=‘t Result: query  SELECT * FROM users WHERE name=‘a’ or ‘t’=‘t’; Query returns information about all users

Taint checker To use it: in your program List String category) {…} 2.Compile your program javac -processor BasicChecker @ImplicitFor(trees = {STRING_LITERAL}) Untainted { }

Defining a type NonNull { }

Defining a type system 1.Type qualifier hierarchy 2.Type introduction rules 3.Other type NonNull { }

Defining a type system 1.Type qualifier hierarchy 2.Type introduction rules 3.Other Nullable.class ) NonNull { }

Defining a type system 1.Type qualifier hierarchy 2.Type introduction rules 3.Other Nullable.class NEW_CLASS, PLUS, BOOLEAN_LITERAL,... } ) NonNull { } new Date() “hello ” + getName() Boolean.TRUE

Defining a type system 1.Type qualifier hierarchy 2.Type introduction rules 3.Other type rules void visitSynchronized(SynchronizedTree node) { ExpressionTree expr = node.getExpression(); AnnotatedTypeMirror type = getAnnotatedType(expr); if (! type.hasAnnotation(NONNULL)) checker.report(Result.failure(...), expr); } synchronized(expr) { … } Warn if expr may be null

Pluggable type-checking Java 7 syntax for type annotations – Write in comments during transition to Java 7 Checker Framework for creating type checkers – Featureful, effective, easy to use, scalable Prevent bugs at compile time Create custom type-checkers Learn more, or download the Checker Framework: (or, web search for “Checker Framework” or “JSR 308”)