| Foreword |
|
xiii | |
| Preface |
|
xvii | |
| About the Author |
|
xxiii | |
| Chapter 1 Running with Scissors |
|
1 | (24) |
|
|
|
4 | (6) |
|
|
|
5 | (1) |
|
|
|
6 | (3) |
|
|
|
9 | (1) |
|
|
|
10 | (6) |
|
|
|
12 | (1) |
|
|
|
12 | (1) |
|
|
|
13 | (1) |
|
|
|
14 | (1) |
|
|
|
15 | (1) |
|
|
|
16 | (3) |
|
|
|
16 | (1) |
|
What Is the Problem with C? |
|
|
17 | (1) |
|
|
|
18 | (1) |
|
|
|
19 | (1) |
|
1.4 Development Platforms |
|
|
19 | (4) |
|
|
|
20 | (1) |
|
|
|
21 | (2) |
|
|
|
23 | (1) |
|
|
|
24 | (1) |
| Chapter 2 Strings |
|
25 | (52) |
|
2.1 String Characteristics |
|
|
25 | (2) |
|
|
|
26 | (1) |
|
2.2 Common String Manipulation Errors |
|
|
27 | (6) |
|
|
|
27 | (2) |
|
|
|
29 | (2) |
|
|
|
31 | (1) |
|
|
|
32 | (1) |
|
String Errors without Functions |
|
|
32 | (1) |
|
2.3 String Vulnerabilities |
|
|
33 | (3) |
|
|
|
34 | (1) |
|
|
|
35 | (1) |
|
2.4 Process Memory Organization |
|
|
36 | (4) |
|
|
|
37 | (3) |
|
|
|
40 | (4) |
|
|
|
44 | (4) |
|
|
|
48 | (3) |
|
2.8 Mitigation Strategies |
|
|
51 | (21) |
|
|
|
51 | (13) |
|
|
|
64 | (3) |
|
|
|
67 | (5) |
|
2.9 Notable Vulnerabilities |
|
|
72 | (2) |
|
|
|
72 | (1) |
|
|
|
72 | (1) |
|
|
|
73 | (1) |
|
|
|
74 | (1) |
|
|
|
75 | (2) |
| Chapter 3 Pointer Subterfuge |
|
77 | (20) |
|
|
|
78 | (1) |
|
|
|
78 | (2) |
|
|
|
80 | (1) |
|
3.4 Modifying the Instruction Pointer |
|
|
81 | (2) |
|
|
|
83 | (1) |
|
|
|
84 | (3) |
|
|
|
87 | (1) |
|
3.8 The atexit() and on_exit() Functions |
|
|
88 | (2) |
|
3.9 The longjmp() Function |
|
|
90 | (2) |
|
|
|
92 | (3) |
|
Structured Exception Handling |
|
|
92 | (2) |
|
System Default Exception Handling |
|
|
94 | (1) |
|
3.11 Mitigation Strategies |
|
|
95 | (1) |
|
|
|
95 | (1) |
|
|
|
95 | (1) |
|
|
|
96 | (1) |
|
|
|
96 | (1) |
| Chapter 4 Dynamic Memory Management |
|
97 | (54) |
|
4.1 Dynamic Memory Management |
|
|
98 | (2) |
|
4.2 Common Dynamic Memory Management Errors |
|
|
100 | (7) |
|
|
|
100 | (2) |
|
Failing to Check Return Values |
|
|
102 | (2) |
|
|
|
104 | (1) |
|
Freeing Memory Multiple Times |
|
|
104 | (2) |
|
Improperly Paired Memory Management Functions |
|
|
106 | (1) |
|
Failure to Distinguish Scalars and Arrays |
|
|
106 | (1) |
|
Improper Use of Allocation Functions |
|
|
107 | (1) |
|
4.3 Doug Lea's Memory Allocator |
|
|
107 | (13) |
|
|
|
108 | (3) |
|
|
|
111 | (6) |
|
Double-Free Vulnerabilities |
|
|
117 | (3) |
|
|
|
120 | (1) |
|
|
|
120 | (18) |
|
Memory Management in Win32 |
|
|
120 | (3) |
|
|
|
123 | (3) |
|
|
|
126 | (3) |
|
|
|
129 | (4) |
|
|
|
133 | (1) |
|
|
|
134 | (3) |
|
|
|
137 | (1) |
|
4.5 Mitigation Strategies |
|
|
138 | (8) |
|
|
|
138 | (1) |
|
Consistent Memory Management Conventions |
|
|
138 | (1) |
|
|
|
139 | (1) |
|
|
|
140 | (1) |
|
|
|
141 | (1) |
|
|
|
142 | (1) |
|
|
|
142 | (1) |
|
|
|
143 | (2) |
|
|
|
145 | (1) |
|
4.6 Notable Vulnerabilities |
|
|
146 | (3) |
|
CVS Buffer Overflow Vulnerability |
|
|
147 | (1) |
|
Microsoft Data Access Components (MDAC) |
|
|
147 | (1) |
|
|
|
148 | (1) |
|
Vulnerabilities in MIT Kerberos 5 |
|
|
149 | (1) |
|
|
|
149 | (1) |
|
|
|
149 | (2) |
| Chapter 5 Integer Security |
|
151 | (52) |
|
|
|
152 | (7) |
|
|
|
152 | (1) |
|
|
|
153 | (4) |
|
|
|
157 | (2) |
|
|
|
159 | (5) |
|
|
|
159 | (1) |
|
|
|
160 | (1) |
|
Conversions From Unsigned Integer Types |
|
|
161 | (1) |
|
Conversions From Signed Integer Types |
|
|
161 | (1) |
|
Signed or Unsigned Characters |
|
|
162 | (2) |
|
Usual Arithmetic Conversions |
|
|
164 | (1) |
|
5.3 Integer Error Conditions |
|
|
164 | (3) |
|
|
|
164 | (2) |
|
|
|
166 | (1) |
|
|
|
167 | (1) |
|
|
|
167 | (14) |
|
|
|
169 | (3) |
|
|
|
172 | (2) |
|
|
|
174 | (3) |
|
|
|
177 | (4) |
|
|
|
181 | (5) |
|
|
|
182 | (1) |
|
|
|
183 | (1) |
|
|
|
184 | (2) |
|
5.6 Nonexceptional Integer Logic Errors |
|
|
186 | (1) |
|
5.7 Mitigation Strategies |
|
|
187 | (10) |
|
|
|
188 | (1) |
|
|
|
189 | (1) |
|
Compiler-Generated Runtime Checks |
|
|
190 | (1) |
|
|
|
191 | (5) |
|
Arbitrary Precision Arithmetic |
|
|
196 | (1) |
|
|
|
196 | (1) |
|
|
|
197 | (1) |
|
5.8 Notable Vulnerabilities |
|
|
197 | (3) |
|
|
|
197 | (1) |
|
Windows DirectX MIDI Library |
|
|
198 | (1) |
|
|
|
199 | (1) |
|
|
|
200 | (1) |
|
|
|
201 | (2) |
| Chapter 6 Formatted Output |
|
203 | (44) |
|
|
|
204 | (4) |
|
ANSI C Standard Arguments |
|
|
205 | (3) |
|
|
|
208 | (1) |
|
6.2 Formatted Output Functions |
|
|
208 | (5) |
|
|
|
209 | (2) |
|
|
|
211 | (1) |
|
|
|
212 | (1) |
|
6.3 Exploiting Formatted Output Functions |
|
|
213 | (12) |
|
|
|
214 | (1) |
|
|
|
215 | (1) |
|
|
|
216 | (1) |
|
|
|
216 | (2) |
|
|
|
218 | (2) |
|
|
|
220 | (4) |
|
|
|
224 | (1) |
|
|
|
225 | (6) |
|
Thwarting Stack Randomization |
|
|
226 | (1) |
|
Writing Addresses in Two Words |
|
|
227 | (1) |
|
|
|
227 | (4) |
|
6.5 Mitigation Strategies |
|
|
231 | (11) |
|
Dynamic Use of Static Content |
|
|
231 | (1) |
|
Restricting Bytes Written |
|
|
232 | (1) |
|
|
|
233 | (1) |
|
|
|
234 | (1) |
|
|
|
234 | (2) |
|
|
|
236 | (1) |
|
|
|
236 | (1) |
|
|
|
237 | (1) |
|
Modifying the Variadic Function Implementation |
|
|
237 | (2) |
|
|
|
239 | (1) |
|
|
|
240 | (1) |
|
|
|
241 | (1) |
|
|
|
241 | (1) |
|
6.6 Notable Vulnerabilities |
|
|
242 | (1) |
|
Washington University FTP Daemon |
|
|
242 | (1) |
|
|
|
243 | (1) |
|
|
|
243 | (2) |
|
|
|
245 | (2) |
| Chapter 7 File I/O |
|
247 | (28) |
|
|
|
247 | (3) |
|
|
|
248 | (1) |
|
Mutual Exclusion and Deadlock |
|
|
248 | (2) |
|
7.2 Time of Check, Time of Use |
|
|
250 | (2) |
|
7.3 Files as Locks and File Locking |
|
|
252 | (2) |
|
|
|
254 | (8) |
|
Symbolic Linking Exploits |
|
|
255 | (2) |
|
Temporary File Open Exploits |
|
|
257 | (3) |
|
|
|
260 | (1) |
|
|
|
261 | (1) |
|
Nonunique Temp File Names |
|
|
261 | (1) |
|
7.5 Mitigation Strategies |
|
|
262 | (10) |
|
|
|
262 | (4) |
|
Eliminating the Race Object |
|
|
266 | (3) |
|
Controlling Access to the Race Object |
|
|
269 | (2) |
|
|
|
271 | (1) |
|
|
|
272 | (3) |
| Chapter 8 Recommended Practices |
|
275 | (34) |
|
8.1 Secure Software Development Principles |
|
|
277 | (5) |
|
|
|
278 | (1) |
|
|
|
278 | (1) |
|
|
|
278 | (1) |
|
|
|
279 | (1) |
|
|
|
279 | (1) |
|
|
|
279 | (2) |
|
|
|
281 | (1) |
|
Psychological Acceptability |
|
|
281 | (1) |
|
8.2 Systems Quality Requirements Engineering |
|
|
282 | (1) |
|
|
|
283 | (1) |
|
|
|
284 | (2) |
|
8.5 Architecture and Design |
|
|
286 | (2) |
|
8.6 Off-the-Shelf Software |
|
|
288 | (2) |
|
Vulnerabilities in Existing Code |
|
|
288 | (1) |
|
|
|
289 | (1) |
|
|
|
290 | (1) |
|
|
|
291 | (1) |
|
|
|
292 | (3) |
|
|
|
293 | (1) |
|
|
|
294 | (1) |
|
|
|
294 | (1) |
|
|
|
295 | (3) |
|
|
|
296 | (1) |
|
|
|
297 | (1) |
|
|
|
297 | (1) |
|
|
|
298 | (1) |
|
|
|
298 | (4) |
|
|
|
299 | (1) |
|
|
|
299 | (1) |
|
|
|
300 | (1) |
|
Developer Guidelines and Checklists |
|
|
300 | (1) |
|
Independent Security Review |
|
|
301 | (1) |
|
|
|
302 | (2) |
|
|
|
302 | (1) |
|
|
|
303 | (1) |
|
Data Execution Prevention |
|
|
303 | (1) |
|
|
|
304 | (1) |
|
|
|
304 | (3) |
|
|
|
305 | (1) |
|
|
|
306 | (1) |
|
|
|
307 | (1) |
|
|
|
308 | (1) |
| References |
|
309 | (14) |
| Acronyms |
|
323 | (6) |
| Index |
|
329 | |