Writing new FindBugs detectors



Similar documents
Improving Software Quality with Static Analysis and Annotations for Software Defect Detection

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

<Insert Picture Here> What's New in NetBeans IDE 7.2

University of Twente. A simulation of the Java Virtual Machine using graph grammars

ABSTRACT TO FIND BUGS. Department of Computer Science. can be found using simple analysis techniques. We have found that simple static

02 B The Java Virtual Machine

State of the World - Statically Verifying API Usage Rule

Comparing Four Static Analysis Tools for Java Concurrency Bugs

Checking Access to Protected Members in the Java Virtual Machine

Virtual Machines. Case Study: JVM. Virtual Machine, Intermediate Language. JVM Case Study. JVM: Java Byte-Code. JVM: Type System

Ontology Model-based Static Analysis on Java Programs

Nullness Analysis of Java Bytecode via Supercompilation over Abstract Values

Java Virtual Machine Locks

Assessing Tools for Finding Bugs in Concurrent Java

Java SE 7 Programming

Pentesting Java/J2EE, finding remote holes

Data Flow Static Code Analysis Best Practices

Write Barrier Removal by Static Analysis

The Java Virtual Machine (JVM) Pat Morin COMP 3002

UI Performance Monitoring

Structural Typing on the Java Virtual. Machine with invokedynamic

picojava TM : A Hardware Implementation of the Java Virtual Machine

A Comparison of Bug Finding Tools for Java

A Java Virtual Machine Architecture for Very Small Devices

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Continuous Code-Quality Assurance with SAFE

Java SE 7 Programming

Java SE 7 Programming

Monitoring Java enviroment / applications

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

An Overview of Java. overview-1

Common Errors in C/C++ Code and Static Analysis

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

CSC 8505 Handout : JVM & Jasmin

Effective Java Programming. measurement as the basis

Instrumenting Java bytecode

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Iron Chef: John Henry Challenge

SAF: Static Analysis Improved Fuzzing

TESTING WITH JUNIT. Lab 3 : Testing

Application-only Call Graph Construction

Speculative Multithreading in a Java Virtual Machine

TOOL EVALUATION REPORT: FORTIFY

Static Analysis Tools in Industry: Dispatches From the Front Line. Dr. Andy Chou Chief Scientist and Co-founder Coverity, Inc.

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

Checking Access to Protected Members in the Java Virtual Machine

Java Interview Questions and Answers

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

The Effectiveness of Automated Static Analysis Tools for Fault Detection and Refactoring Prediction

Modulo II Qualidade de Software com Maven

Memories of Bug Fixes

CS 111 Classes I 1. Software Organization View to this point:

Linux Kernel. Security Report

STATIC CODE ANALYSIS Alexandru G. Bardas 1

A Brief Introduction to Static Analysis

Platform Independent Dynamic Java Virtual Machine Analysis: the Java Grande Forum Benchmark Suite

Under the Hood: The Java Virtual Machine. Lecture 24 CS 2110 Fall 2011

The Java Virtual Machine Specification. Java SE 8 Edition

Java Mission Control

Habanero Extreme Scale Software Research Project

KAIST Cyber Security Research Center SAR(Security Analysis Report) Date. August 31, Modified

Deadlock Victim. dimanche 6 mai 12

The Darwin Game 2.0 Programming Guide

Java Virtual Machine, JVM

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Evaluation of AgitarOne

No no-argument constructor. No default constructor found

IMPROVING VULNERABILITY MANAGEMENT EFFECTIVENESS WITH APPLICATION SECURITY MONITORING

Understanding and Detec.ng Real- World Performance Bugs

Development Testing for Agile Environments

Chapter 1 Java Program Design and Development

Virtual Machine Learning: Thinking Like a Computer Architect

What s Cool in the SAP JVM (CON3243)

Software Reliability Estimation Based on Static Error Detection

Advanced Java Client API

NetBeans and GlassFish v 2.1 Creating a Healthcare Facility Visual Web Application

Comparing the Effectiveness of Penetration Testing and Static Code Analysis

VisualVM: Integrated and Extensible Troubleshooting Tool for the Java Platform

CSCI E 98: Managed Environments for the Execution of Programs

Improving Software Quality with the Continuous Integration Server Hudson. Dr. Ullrich Hafner Avaloq Evolution AG 8911

Static Code Analysis Procedures in the Development Cycle

Security Monitor Inlining for Multithreaded Java

Java Power Tools. John Ferguson Smart. ULB Darmstadt 1 PI. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

Java Memory Model: Content

Coding in Industry. David Berry Director of Engineering Qualcomm Cambridge Ltd

The Context of Software Development

Replication on Virtual Machines

Static Analysis. Find the Bug! : Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled

Transcription:

Writing new FindBugs detectors Why? You may find bug patterns in your own code How? Inspect bytecode There are many ways to implement a FindBugs detector Often, simple techniques (e.g., sequential scan) suffice

Basic Approach (! important ) Start with a bug Write the simplest possible detector that might find similar bugs Evaluate: does it find enough interesting bugs without too many false positives? Refine: improve analysis and FP suppression heuristics Repeat steps 3 and 4 until you get something acceptable or you give up on the idea

Example Bug Don t use String literals for the synchronized blocks! static private final String LOCK = "LOCK"; void somemethod() { synchronized(lock) {... }} This example from Jetty If other code synchronizes on same String Possible deadlock

Writing a detector Add test case Bytecode: LDC "LOCK" DUP ASTORE 1 MONITORENTER Let s use opcode stack. Could also look for bytecode sequence.

SynchronizationOnSharedBuiltinConstant public void sawopcode(int seen) { if (seen == MONITORENTER) { OpcodeStack.Item top = stack.getstackitem(0); ("; top.getsignature().equals("ljava/lang/string ) if ( String && top.getconstant() instanceof bugreporter.reportbug(new BugInstance(this, "DL_SYNCHRONIZATION_ON_SHARED_CONSTANT", ( NORMAL_PRIORITY ( addclassandmethod(this. ( addstring((string)constant..addsourceline(this)); } }

Results Found issue fixed in Jetty-352. Jetty-352 didn t fix all occurrences in Jetty (Jetty-362). Also found occurrences in Eclipse, glassfish, Sun s JDK, netbeans, nutch, oc4j, weblogic, websphere Not bad for 20 minutes work

Why simple techniques work We aren t trying to prove anything about the code Simple mistakes generally result in mistakes that are easy to find javac does minimal optimization/transformation Simple analysis produces results that are easy to triage

Bytecode frameworks All FindBugs detectors work by analyzing bytecode. Supported frameworks: BCEL (http://jakarta.apache.org/bcel/); DOM-like API ASM (http://asm.objectweb.org/); SAX-like API Currently, much of the supporting FindBugs infrastructure is based on BCEL. Support for ASM-based analyses and detectors is experimental.

Types of detectors Most FindBugs detectors use one of the following implementation techniques: Inspecting class/method/field structure Micropatterns: simple bytecode patterns Stack-based patterns Dataflow analysis Interprocedural analysis Each technique is supported by ready-made base classes and support infrastructure

Inspecting class/method/field structure Some detectors do not require code analysis. Examples: Find classes that override equals() but not () hashcode Find method naming problems (e.g., hashcode() (() hashcode instead of

Micropatterns: simple bytecode patterns E.g., unconditional wait: Source code synchronized (lock) { lock.wait();... } Bytecode in class file ALOAD 0 GETFIELD A.lock DUP ASTORE 1 MONITORENTER ALOAD 0 GETFIELD A.lock INVOKEVIRTUAL Object.wait()V

Detector states

Stack-based patterns Micropatterns where the values on the operand stack are significant. Example: As seen earlier: look for monitorenter on constant String value Typical implementation strategy: Inquire about values on operand stack Warn when suspicious instruction sequence/stack values seen

Dataflow analysis Use intraprocedural dataflow analysis to infer (probable) facts within methods. You may need to dust off your copy of the Dragon book. Examples: Find dereferences of null values Find field accesses not consistently protected by a lock

Interprocedural analysis Summarize method behavior, and use that summary at each call site. Examples: Method parameters that are unconditionally dereferenced. Return values that are always nonnull. Methods that always throw an exception.

For more information http://code.google.com/p/findbugs-tutorials Slides from PLDI tutorial, Using FindBugs for Research In-depth discussion of writing FindBugs detectors Source code for demo plugin with two detectors