]> andersk Git - splint.git/blame - BUFFERCHECKING
Changes for the OS/2 port: cpplib.c (fixed cstring_replaceAll()
[splint.git] / BUFFERCHECKING
CommitLineData
15b3d2b2 1 Buffer Overflow Checking
2 David Larochelle
3 15 August 2001
4
5
6This is a preliminary guide to the buffer overflow checking in LCLint
7Version 3.0. This alpha version contains additional checking not
8documented in the manual for LCLint 2.5.
9
10Although this document provides a quick introduction for the new
11features of LCLint it is not intended as a substitute for the LCLint
12manual. We recommend that users unfamiliar with LCLint consult the
13LCLint user guides in addition to this document.
14
15The types of errors which LCLint reports can be controlled flags.
16Theses flags can be set on the commands line or in .lclintrc files. A
17flags by giving LCLint the +flagname option on the command line or in a
18.lclintrc file where flagname is the name of the flag. Similarly flags
19are unset with -flagname.
20
21Overview
22========
23
24LCLint detects buffer overflow errors by generating precondition and
25postcondition constraints at the expression level. We resolve
26constraints using post conditions from previous statements. We generate
27an error message for any constraints which we are unable to resolve at
28the top of a function.
29
30All checking takes place within functions. Interprocedural properties
31are checked using annotations. Annotated versions of the standard
32libraries are provided innerally.
33
34The new annotations allow programmers to explicitly state function
35preconditions and postconditions using requires and ensures clauses. We
36can use these clauses to describe assumptions about buffers that are
37passed to functions and constrain the state of buffers when functions
38return. For the analyses described here two kinds of assumptions and
39constraints are used: maxSet, and maxRead.
40
41When used in a requires clause, the maxSet annotation describes
42assumptions about the lowest and highest indices of a buffer that may be
43safely used as an lvalue (e.g., on the left-hand side of an assignment).
44For example, consider a function with an array parameter a and an
45integer parameter i that has a precondition requires maxSet(a) >= i.
46The analysis assumes that at the beginning of the function body, a[i]
47may be used as an lvalue. If a[i+1] were used before any modifications
48to the value of a or i, LCLint would generate a warning since the
49function preconditions are not sufficient to guarantee that a[i+1] can
50be used safely as an lvalue. Arrays in C start with index 0, so the
51declaration char buf[MAXSIZE] generates the constraints maxSet(buf) =
52MAXSIZE - 1 and minSet(buf) = 0. Similarly, the maxRead constraint
53indicates the maximum indices of a buffer that may be read safely. The
54value of maxRead for a given buffer is always less than or equal to the
55value of maxSet. In cases where there are elements of the buffer have
56not yet been initialized, the value of maxRead may be lower than the
57value of maxSet.
58
59Checking is controlled by the following flags. If the arraybounds flag
60is set LCLint will report potential array bounds. THIS FLAG MUST BE SET
61IN ORDER FOR BUFFER OVERFLOW ERRORS TO BE REPORTED. There are a number
62of additional options which can be used to fine tune checking.
63
64If the +arrayboundsread is set LCLint will report cases in which an
65index past the end of an array or buffer is read. The default is to
66only report cases in which data is written. Out of bounds reads are
67less dangerous than out of bounds writes but are still security
68problems.
69
70The following are used to fine tune the checking. If the
71constraintlocation flag is set LCLint will include the expression which
72causes LCLint to generate the unresolved constraint in an error message.
73We recommend this options. The orconstraint is used to perform slightly
74more accurate checking by using disjuction internally. The performance
75cost is minimal so we recommend this option.
76
77Handling spurious messages
78==========================
79
80LCLint will occasionally report spurious error messages. If you see an
81error message that you believe to be incorrect first see if you can
82correct the problem by adding additional precondition annotations. For
83function with no preconditions LCLint assumes that the function is safe
84under all conditions. Also consider rewriting the code. Code that is
85hard for LCLint to understand is often hard was humans to understand as
86well. You may want to improve the readability and clarity is the code.
87
88If you are sure that the message is spurious you can suppress the
89message. Adding the /*@i@*/ annotation to a line causes LCLint to
90suppers all errors generated by the line. Flags can also be set and
91unset within a program. /*@-flagname@*/ sets a flag to
92false. /*@+flagname@*/ sets a flag to true and /*@=flagname@*/ returns a
93flag to its previous state.
94
95For example /*@-arroundboundsread@*/ str2[i] = str[i];
96/*@=arroundboundsread@*/ would suppress error involving out of bounds
97reads for the code fragment.
98
99Frequently Asked Questions
100==========================
101
102I have a function with many buffer overflows but LCLint only reports one
103error?
104
105LCLint tries to avoid printing redundant error messages. We don't print
106two constraints if satifying one constraint would satisify another.
107
108LCLint crashes or complains about a bug?
109
110Please report the problem to lclint-bug@cs.virginia.edu
111
112Where can I find more information about LCLint?
113
114The LCLint web site http://lclint.cs.virginia.edu contains a lot of
115useful documentation, including a paper describing the LCLint extensions
116for buffer overflow checking. The lclint web site also contains
117information on lclint mailing lists.
118
119
120
121
122
123
This page took 0.093303 seconds and 5 git commands to generate.