14-jun-05white elephant gmbh1 ada bug finder. 14-jun-05white elephant gmbh2 ada bug finder the ada...

48
14-Jun-05 White Elephant GmbH 1 Ada Bug Ada Bug Finder Finder

Upload: tracy-kelly

Post on 23-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 1

Ada Bug Ada Bug FinderFinder

Page 2: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 2

Ada Bug FinderAda Bug Finder

The Ada Bug Finder is a Windows application that searches Ada code for recognisable bug patterns

Page 3: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 3

PresentationPresentation

Bug Finders Ada Bug Finder v1.4 Ada Bug Patterns Results Free software for you to try out!

Page 4: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 4

InspirationInspiration

“Finding Bugs is Easy”

By David Hovemeyer and William Pugh

Presented October 2004 at OOPSLASpecific to Java Bug Patterns

Page 5: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 5

Bug Pattern - Bug Pattern - DefinitionDefinition

A bug pattern is a code idiomthat is likely to be an error. David Hovemeyer and William Pugh

Syntactically correct but probably not what the author intended.

Page 6: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 6

Concept Concept

Premise: Bugs exist in production code

Search existing Ada code base for bug patterns.

Page 7: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 7

Bugs in Production Bugs in Production CCodeode

Why?In code that is rarely executedSymptoms hard to reproduceNo access to development staff

Page 8: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 8

A “A “FindFind bugsbugs”” Utility Utility

Should use simple patternsNeed not be 100% correctFalse Positives are to be expectedNo guarantee that every situation

coveredOvernight background job – Speed

not an issue

Page 9: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 9

Trade-offsTrade-offs

Compilers could do more– Increased compilation time

Bug finder utility could do more or raise fewer false positives– Increased development costs

Page 10: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 10

Ada Bug Finder v1.4Ada Bug Finder v1.4

Result of a small 140 hour projectAs yet only detects 8 bug patternsOptionally checks 7 style rules

Page 11: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 11

False PositivesFalse Positives

ABF doesn’t always get it right!– Implementation trade-off– Bad or over-complex style

Exercise care when modifying code!Mark code with special comment to

prevent ABF reporting

Page 12: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 12

Code MarkingCode Marking - Example - Example

Page 13: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 13

Recognised Ada Bug PatternsRecognised Ada Bug Patterns

1. Illogical Operator Rename

2. Code Not Reachable

3. Exception Not Raised

4. Unused Unit

5. Unused Declaration

6. Null Pointer

7. Non Short Circuit

8. Wrong Granularity

Page 14: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 14

1. Illogical Operator Rename1. Illogical Operator Rename

In Ada83, where there is no use type clause, operators are often renamed to avoid the use of prefixed notation

Clumsy cut & paste editing might result in renaming an operator to be something totally different. The compiler allows this although it is highly unlikely to be what the author intended

Page 15: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 15

IOR - ExampleIOR - Example

Page 16: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 16

2. Code Not Reachable2. Code Not Reachable

Code placed after an unconditionalRaiseReturnExit

Some compilers (Gnat) detect this.

Page 17: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 17

CNR - ExampleCNR - Example

Page 18: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 18

3. Exception Not Raised3. Exception Not Raised

An exception is declared but never raised

Exception handled but never raised

Page 19: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 19

ENR – ExampleENR – Example of False Positive of False Positive

Page 20: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 20

4. Unused Unit4. Unused Unit

Package imported but never used Procedure, function or package defined

but neither exported nor used locally

False positives: Undetected default generic subprogram

parameter Conditional compilation selected code

destined for a different target

Page 21: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 21

UU – ExampleUU – Example of False Positive of False Positive

Page 22: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 22

5. Unused Declaration5. Unused Declaration

Type, Constant or Variable declared but never used

Why? History Confusion – Similar names OverloadingFalse positive: Required because controlled type or

default initialisation has an effect

Page 23: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 23

UD – ExampleUD – Example of False Positive of False Positive

Page 24: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 24

6. Null Pointer6. Null Pointer

Code explicitly checks for null then dereferences the pointer

Unbelievable?Not a compiler requirement.

Some make checks

None do the job properly!

Page 25: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 25

NP - ExampleNP - Example

Page 26: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 26

7. Non Short Circuit7. Non Short Circuit

and used instead of and thenor used instead of or else

TypicallyTest if index in range then use itTest if pointer not null then

dereference it

Page 27: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 27

NSC - ExampleNSC - Example

Page 28: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 28

8. Wrong Granularity8. Wrong Granularity

Size attribute outside of an expression Unlikely usage because hardly anything

requires the size of an object in bits!

Typically An imported API (e.g. Windows) requires

the address and size of a buffer in bytes. If this buffer size is supplied as bits, a buffer overrun may occur!

Page 29: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 29

WGWG - Example - Example

Page 30: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 30

The Ada Bug FinderThe Ada Bug Finder Utility Utility

Written in Ada95Uses Ada Parser to detect patternsReportsOptionsStyle

Page 31: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 31

Screen ShotScreen Shot

Page 32: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 32

ABFABF - Reports - Reports

TextComma Delimited

Page 33: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 33

ABFABF - Options - Options

Gnat ExtensionsPreparation Phase (Second pass to

reduce false positives at the expense of speed)

Page 34: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 34

Style RulesStyle Rules

Not bugs as such but coding practices that lead to bugs or make bugs harder to find.

1. Character Not Portable2. Handle Task Exceptions3. No Declaration Overloading4. No Goto Statements5. No Use Clause6. No Variables in Specification7. Superfluous Code Mark

Page 35: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 35

Other Other recognisedrecognised bug patterns bug patterns

1. Division by Zero

2. Raise after Assignment

3. Redundant Comparison to Null

4. Symmetrical Comparison

Page 36: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 36

1. Division by Zero1. Division by Zero

Code explicitly checks for zero then uses it for division.

Page 37: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 37

DBZDBZ - Example - Example

Page 38: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 38

2.Raise after assignment2.Raise after assignment

Leaving a procedure abnormally nullifies assignment to in-out or out parameters

Page 39: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 39

RAARAA - Example - Example

Page 40: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 40

3. Redundant Comparison to null3. Redundant Comparison to null

Comparing a pointer to null after it has been dereferenced is redundant

Indicates confusion. Either the check is truly redundant or the previous dereference should have been first checked.

Page 41: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 41

RCNRCN - Example - Example

Page 42: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 42

4. Symmetrical Comparison4. Symmetrical Comparison

When both sides of a comparison are identical

Page 43: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 43

SCSC - Example - Example

Page 44: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 44

ResultsResults

Sources Files Cnr Enr Ior Nsc Np Se Ud Uu Wg Styles

UniControl 1.3 149 15 2 36 25 1 25

ILTIS 3622.12.36 4539 25 267 2 131 11 1672 317 23 2109

Aonix 7.2.2 828 2 18 4 196 23 5 1080

Gnat GCC 3.15pGps 1.4

2976 1 55 4 1 8 255 236 3 14070

AI-302 147 1 1 1 240

Page 45: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 45

ResultsResults

Bugs were found in all the code bases we searched.

Most were in code that was seldom if ever executed (e.g. Error handling)

Some were severe! Reluctance to change production code

that been accepted and that appears to function correctly.

Can be used as a development tool.

Page 46: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 46

Results (Style Violations)Results (Style Violations)

Sources Total Cnp Hte Ndo Ngs Npuc Nvis Scm

UniControl 1.3 25 9 16

Iltis 3622.12.36 2109 24 22 1443 169 451

Aonix 7.2.2 1080 16 20 2 475 567

Gnat GCC 3.15pGps 1.3

14070 17 314 462 11303 1974

AI-302 240 2 3 233 2

Page 47: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 47

Any other ideas?Any other ideas?

After you find a bug ask yourself whether it could have been found automatically by looking for a “Simple Pattern”

If so then let’s include it into ABF and see if anyone else has made the same bug!

Page 48: 14-Jun-05White Elephant GmbH1 Ada Bug Finder. 14-Jun-05White Elephant GmbH2 Ada Bug Finder The Ada Bug Finder is a Windows application that searches Ada

14-Jun-05 White Elephant GmbH 48

Where to get itWhere to get it

Not open source but freely available for use

Download fromwww.white-elephant.ch

Feedback appreciated.– Results– Suggestions for new patterns– Excessive false positives.