Docsity

Finding Bugs in Software: Approaches and Techniques, Study notes of Computer Science

Toggle sidebar
bg1
1
CS553 Lecture Finding Bugs 2
Finding Bugs
Last time
โ€“ Run-time reordering transformations
Today
โ€“ Program Analysis for finding bugs, especially security bugs
โ€“ problem specification
โ€“ motivation
โ€“ approaches
โ€“ remaining issues
CS553 Lecture Finding Bugs 3
Problem
What is a bug?
โ€“ a path in the code that causes a run-time exception
โ€“ a path through the code that causes incorrect results
Issues
โ€“ exponential many paths
โ€“ cannot statically determine the path a program will take
โ€“ โ€œProgram testing can be used to find the presence of bugs, but never to show their
absence.โ€ [Dijkstra 1972]
Undecidability
โ€“ soundness and completeness together is undecidable
โ€“ confusion in literature: which is which?
โ€“ every reported error is genuine (no false positives)
โ€“ if the program has any errors then the checker will report some error (no false
negatives)
CS553 Lecture Finding Bugs 4
Motivation for the Automatic Detection of Bugs
Time spent in program maintenance
โ€“ most software engineers spend the majority of their time doing
maintenance
โ€“ most time spent doing maintenance is time spent debugging
Costs due to bugs that allow security exploits (approximations published
at CNET News.com, Jan 31 2003)
โ€“ Slammer (950 million)
โ€“ Code Red (2.6 billion productivity loss)
โ€“ LoveLetter (8.8 billion)
โ€“ Klez virus (9.0 billion)
CS553 Lecture Finding Bugs 5
Approaches to Finding Bugs
Approaches
โ€“ strengthening the type system
โ€“ static analysis to detect bug patterns
โ€“ automated theorem proving
โ€“ dynamic analysis
โ€“ catch errors before they occur
โ€“ find the cause for failures after the fact
Evaluating the different approaches
โ€“ how many false positives?
โ€“ how many false negatives?
โ€“ extent of user intervention or ease of use
โ€“ efficiency of approach
pf3
pf4

Partial preview of the text

Download Finding Bugs in Software: Approaches and Techniques and more Study notes Computer Science in PDF only on Docsity!

CS553 Lecture Finding Bugs 2

Finding Bugs

Last time

  • Run-time reordering transformations Today
  • Program Analysis for finding bugs, especially security bugs
  • problem specification
  • motivation
  • approaches
  • remaining issues CS553 Lecture Finding Bugs 3

Problem

What is a bug?

  • a path in the code that causes a run-time exception
  • a path through the code that causes incorrect results Issues
  • exponential many paths
  • cannot statically determine the path a program will take
  • โ€œProgram testing can be used to find the presence of bugs, but never to show their absence.โ€ [Dijkstra 1972] Undecidability
  • soundness and completeness together is undecidable
  • confusion in literature: which is which?
  • every reported error is genuine (no false positives)
  • if the program has any errors then the checker will report some error (no false negatives) CS553 Lecture Finding Bugs 4

Motivation for the Automatic Detection of Bugs

Time spent in program maintenance

  • most software engineers spend the majority of their time doing maintenance
  • most time spent doing maintenance is time spent debugging Costs due to bugs that allow security exploits (approximations published at CNET News.com, Jan 31 2003)
  • Slammer (950 million)
  • Code Red (2.6 billion productivity loss)
  • LoveLetter (8.8 billion)
  • Klez virus (9.0 billion) CS553 Lecture Finding Bugs 5

Approaches to Finding Bugs

Approaches

  • strengthening the type system
  • static analysis to detect bug patterns
  • automated theorem proving
  • dynamic analysis
    • catch errors before they occur
    • find the cause for failures after the fact Evaluating the different approaches
  • how many false positives?
  • how many false negatives?
  • extent of user intervention or ease of use
  • efficiency of approach

CS553 Lecture Finding Bugs 6

Example Bugs

null dereference if (p==null) { p->open() } array bounds error int a[20]; a[20] = ...; untrusted access

  • format string vulnerability fgets(buffer, size, file); printf(buffer); CS553 Lecture Finding Bugs 7

Type Qualifiers [Shankar, et al โ€™01]

Idea

  • Add tainted and untainted types to library function signatures
  • Use type constraint solver to find errors
    • Errors are type mismatches Issues
  • What is the type of strdup()?
  • What happens when the value of strings change? fgets( tainted char *buffer, int size, FILE *f); printf( untainted char *format,.. .); CS553 Lecture Finding Bugs 8

Static Analysis

FindBugs

  • project at University of Maryland for finding bugs in Java
  • they observe that bugs found in student programs are also found in production code
  • implementation steps:
    1. think of the simplest technique that would find occurrences of the bug
    2. implement it
    3. apply it to real software. Hopefully find some real bugs. Will probably produce some false warnings.
    4. add heuristics to reduce percentage of false warnings Their experience: new detectors can usually be implemented quickly (somewhere between a few minutes and a few days). Often, detectors find more bugs than you would expect Kinds of analysis in implementing detectors:
  • Examination of method names, signatures, class hierarchy
  • Linear scan of bytecode instructions using a state machine
  • Method control flow graphs, dataflow anlysis
  • No interprocedural flow analysis or sophisticated heap analysis CS553 Lecture Finding Bugs 9

How FindBugs Handles the Example Bugs

Null pointer dereferences

  • found 37 in rt.jar 1.5-b59, 55 in eclipse-3. Array bounds checking
  • not an issue in Java Untrusted Code
  • Can static fields (or the objects they refer to) be modified by untrusted code?
  • Public, non-final static fields
  • Public static fields pointing to an array
  • Warnings: 254 in rt.jar 1.5-b59, 967 in eclipse-3.

CS553 Lecture Finding Bugs 14

Remaining Issues

Evaluation of new techniques is tedious

  • must have a human determine if problem reported is an actual bug
  • getting developers to fix the bug is another battle
  • how can we determine if one bug detection system is better than another?
    • might analyze different languages
    • experiments performed on different benchmarks (version of the software make a different benchmark)
    • approach: people are starting to put together bug benchmarks Static Analysis
  • whole program versus partial program analysis
  • quality of alias analysis affects quality number of false positives CS553 Lecture Finding Bugs 15

Concepts

Approaches to bug detection

  • augmenting the type system
  • static analysis
  • automated theorem proving
  • dynamic analysis Comparing bug detection techniques is tricky
  • what is considered a real bug?
  • how can we compare false positives with false negatives? how can we determine them at all CS553 Lecture Finding Bugs 16

Next Time

Lecture

  • This is it!
    • review of what we covered this quarter
    • how does it all fit together?
    • any requests?