1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <title>Available Checkers
</title>
6 <link type=
"text/css" rel=
"stylesheet" href=
"menu.css">
7 <link type=
"text/css" rel=
"stylesheet" href=
"content.css">
8 <script type=
"text/javascript" src=
"scripts/menu.js"></script>
9 <script type=
"text/javascript" src=
"scripts/expandcollapse.js"></script>
10 <style type=
"text/css">
11 tr:first-child
{ width:20%; }
14 <body onload=
"initExpandCollapse()">
17 <!--#include virtual="menu.html.incl"-->
20 <h1>Available Checkers
</h1>
21 The analyzer performs checks that are categorized into families or
"checkers". The
22 default set of checkers covers a variety of checks targeted at finding security
23 and API usage bugs, dead code, and other logic errors. See the
24 <a href =
"#default_checkers">Default Checkers
</a> list below. In addition to
25 these, the analyzer contains a number of
<a href =
"alpha_checks.html">
26 Experimental (Alpha) Checkers
</a>.
28 <h3>Writeups with examples of some of the bugs that the analyzer finds
</h3>
30 <li><a href=
"http://www.mobileorchard.com/bug-finding-with-clang-5-resources-to-get-you-started/">Bug Finding With Clang:
5 Resources To Get You Started
</a></li>
31 <li><a href=
"http://fruitstandsoftware.com/blog/index.php/2008/08/finding-memory-leaks-with-the-llvmclang-static-analyzer/#comment-2">Finding Memory Leaks With The LLVM/Clang Static Analyzer
</a></li>
32 <li><a href=
"http://www.rogueamoeba.com/utm/2008/07/14/the-clang-static-analyzer/">Under the Microscope - The Clang Static Analyzer
</a></li>
33 <li><a href=
"http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html">Mike Ash - Using the Clang Static Analyzer
</a></li>
36 <h2 id=
"default_checkers">Default Checkers
</h2>
38 <li><a href=
"#core_checkers">Core Checkers
</a> model core language features and perform general-purpose checks such as division by zero, null pointer dereference, usage of uninitialized values, etc.
</li>
39 <li><a href=
"#cplusplus_checkers">C++ Checkers
</a> perform C++-specific checks
</li>
40 <li><a href=
"#deadcode_checkers">Dead Code Checkers
</a> check for unused code
</li>
41 <li><a href=
"#osx_checkers">OS X Checkers
</a> perform Objective-C-specific checks and check the use of Apple's SDKs (OS X and iOS)
</li>
42 <li><a href=
"#security_checkers">Security Checkers
</a> check for insecure API usage and perform checks based on the CERT Secure Coding Standards
</li>
43 <li><a href=
"#unix_checkers">Unix Checkers
</a> check the use of Unix and POSIX APIs
</li>
46 <!------------------------------------ core ----------------------------------->
47 <h3 id=
"core_checkers">Core Checkers
</h3>
48 <table class=
"checkers">
49 <colgroup><col class=
"namedescr"><col class=
"example"></colgroup>
50 <thead><tr><td>Name, Description
</td><td>Example
</td></tr></thead>
53 <tr><td><div class=
"namedescr expandable"><span class=
"name">
54 core.CallAndMessage
</span><span class=
"lang">
55 (C, C++, ObjC)
</span><div class=
"descr">
56 Check for logical errors for function calls and Objective-C message expressions
57 (e.g., uninitialized arguments, null function pointers).
</div></div></td>
58 <td><div class=
"exampleContainer expandable">
59 <div class=
"example"><pre>
69 f(s); // warn: passed-by-value arg contain uninitialized data
72 <div class=
"example"><pre>
76 foo(); // warn: function pointer is uninitialized
79 <div class=
"example"><pre>
84 foo(); // warn: function pointer is null
87 <div class=
"example"><pre>
96 pc-
>f(); // warn: object pointer is uninitialized
99 <div class=
"example"><pre>
108 pc-
>f(); // warn: object pointer is null
111 <div class=
"example"><pre>
113 @interface MyClass : NSObject
114 @property (readwrite,assign) id x;
115 - (long double)longDoubleM;
120 long double ld1 = [obj1 longDoubleM];
121 // warn: receiver is uninitialized
124 <div class=
"example"><pre>
126 @interface MyClass : NSObject
127 @property (readwrite,assign) id x;
128 - (long double)longDoubleM;
133 id i = obj1.x; // warn: uninitialized object pointer
136 <div class=
"example"><pre>
138 @interface Subscriptable : NSObject
139 - (id)objectAtIndexedSubscript:(unsigned int)index;
142 @interface MyClass : Subscriptable
143 @property (readwrite,assign) id x;
144 - (long double)longDoubleM;
149 id i = obj1[
0]; // warn: uninitialized object pointer
151 </pre></div></div></td></tr>
154 <tr><td><div class=
"namedescr expandable"><span class=
"name">
155 core.DivideZero
</span><span class=
"lang">
156 (C, C++, ObjC)
</span><div class=
"descr">
157 Check for division by zero.
</div></div></td>
158 <td><div class=
"exampleContainer expandable">
159 <div class=
"example"><pre>
162 int x =
1 / z; // warn
165 <div class=
"example"><pre>
168 int y = x %
0; // warn
170 </pre></div></div></td></tr>
173 <tr><td><div class=
"namedescr expandable"><span class=
"name">
174 core.NonNullParamChecker
</span><span class=
"lang">
175 (C, C++, ObjC)
</span><div class=
"descr">
176 Check for null pointers passed as arguments to a function whose arguments are
177 marked with the
<code>nonnull
</code> attribute.
</div></div></td>
178 <td><div class=
"exampleContainer expandable">
179 <div class=
"example"><pre>
180 int f(int *p) __attribute__((nonnull));
186 </pre></div></div></td></tr>
189 <tr><td><div class=
"namedescr expandable"><span class=
"name">
190 core.NullDereference
</span><span class=
"lang">
191 (C, C++, ObjC)
</span><div class=
"descr">
192 Check for dereferences of null pointers.
</div></div></td>
193 <td><div class=
"exampleContainer expandable">
194 <div class=
"example"><pre>
200 int x = p[
0]; // warn
203 <div class=
"example"><pre>
210 <div class=
"example"><pre>
219 int k = pc-
>x; // warn
222 <div class=
"example"><pre>
232 obj-
>x =
1; // warn
234 </pre></div></div></td></tr>
237 <tr><td><div class=
"namedescr expandable"><span class=
"name">
238 core.StackAddressEscape
</span><span class=
"lang">
239 (C)
</span><div class=
"descr">
240 Check that addresses of stack memory do not escape the function.
</div></div></td>
241 <td><div class=
"exampleContainer expandable">
242 <div class=
"example"><pre>
246 char const str[] =
"string";
250 <div class=
"example"><pre>
252 return __builtin_alloca(
12); // warn
255 <div class=
"example"><pre>
261 </pre></div></div></td></tr>
264 <tr><td><div class=
"namedescr expandable"><span class=
"name">
265 core.UndefinedBinaryOperatorResult
</span><span class=
"lang">
266 (C)
</span><div class=
"descr">
267 Check for undefined results of binary operators.
</div></div></td>
268 <td><div class=
"exampleContainer expandable">
269 <div class=
"example"><pre>
272 int y = x +
1; // warn: left operand is garbage
274 </pre></div></div></td></tr>
277 <tr><td><div class=
"namedescr expandable"><span class=
"name">
278 core.VLASize
</span><span class=
"lang">
279 (C)
</span><div class=
"descr">
280 Check for declarations of VLA of undefined or zero size.
</div></div></td>
281 <td><div class=
"exampleContainer expandable">
282 <div class=
"example"><pre>
285 int vla1[x]; // warn: garbage as size
288 <div class=
"example"><pre>
291 int vla2[x]; // warn: zero size
293 </pre></div></div></td></tr>
296 <tr><td><div class=
"namedescr expandable"><span class=
"name">
297 core.uninitialized.ArraySubscript
</span><span class=
"lang">
298 (C)
</span><div class=
"descr">
299 Check for uninitialized values used as array subscripts.
</div></div></td>
300 <td><div class=
"exampleContainer expandable">
301 <div class=
"example"><pre>
304 int x = a[i]; // warn: array subscript is undefined
306 </pre></div></div></td></tr>
309 <tr><td><div class=
"namedescr expandable"><span class=
"name">
310 core.uninitialized.Assign
</span><span class=
"lang">
311 (C)
</span><div class=
"descr">
312 Check for assigning uninitialized values.
</div></div></td>
313 <td><div class=
"exampleContainer expandable">
314 <div class=
"example"><pre>
317 x |=
1; // warn: left expression is unitialized
319 </pre></div></div></td></tr>
322 <tr><td><div class=
"namedescr expandable"><span class=
"name">
323 core.uninitialized.Branch
</span><span class=
"lang">
324 (C)
</span><div class=
"descr">
325 Check for uninitialized values used as branch conditions.
</div></div></td>
326 <td><div class=
"exampleContainer expandable">
327 <div class=
"example"><pre>
333 </pre></div></div></td></tr>
336 <tr><td><div class=
"namedescr expandable"><span class=
"name">
337 core.uninitialized.CapturedBlockVariable
</span><span class=
"lang">
338 (C)
</span><div class=
"descr">
339 Check for blocks that capture uninitialized values.
</div></div></td>
340 <td><div class=
"exampleContainer expandable">
341 <div class=
"example"><pre>
344 ^{ int y = x; }(); // warn
346 </pre></div></div></td></tr>
349 <tr><td><div class=
"namedescr expandable"><span class=
"name">
350 core.uninitialized.UndefReturn
</span><span class=
"lang">
351 (C)
</span><div class=
"descr">
352 Check for uninitialized values being returned to the caller.
</div></div></td>
353 <td><div class=
"exampleContainer expandable">
354 <div class=
"example"><pre>
359 </pre></div></div></td></tr>
363 <!------------------------------------ C++ ------------------------------------>
364 <h3 id=
"cplusplus_checkers">C++ Checkers
</h3>
365 <table class=
"checkers">
366 <colgroup><col class=
"namedescr"><col class=
"example"></colgroup>
367 <thead><tr><td>Name, Description
</td><td>Example
</td></tr></thead>
370 <tr><td><div class=
"namedescr expandable"><span class=
"name">
371 cplusplus.NewDelete
</span><span class=
"lang">
372 (C++)
</span><div class=
"descr">
373 Check for double-free, use-after-free and offset problems involving C++
<code>
374 delete
</code>.
</div></div></td>
375 <td><div class=
"exampleContainer expandable">
376 <div class=
"example"><pre>
379 void testUseMiddleArgAfterDelete(int *p) {
381 f(p); // warn: use after free
384 <div class=
"example"><pre>
391 SomeClass *c = new SomeClass;
393 c-
>f(); // warn: use after free
396 <div class=
"example"><pre>
398 int *p = (int *)__builtin_alloca(sizeof(int));
399 delete p; // warn: deleting memory allocated by alloca
402 <div class=
"example"><pre>
406 delete p; // warn: attempt to free released
409 <div class=
"example"><pre>
412 delete
&i; // warn: delete address of local
415 <div class=
"example"><pre>
419 // warn: argument to 'delete[]' is offset by
4 bytes
420 // from the start of memory allocated by 'new[]'
422 </pre></div></div></td></tr>
426 <!--------------------------------- dead code --------------------------------->
427 <h3 id=
"deadcode_checkers">Dead Code Checkers
</h3>
428 <table class=
"checkers">
429 <colgroup><col class=
"namedescr"><col class=
"example"></colgroup>
430 <thead><tr><td>Name, Description
</td><td>Example
</td></tr></thead>
433 <tr><td><div class=
"namedescr expandable"><span class=
"name">
434 deadcode.DeadStores
</span><span class=
"lang">
435 (C)
</span><div class=
"descr">
436 Check for values stored to variables that are never read afterwards.
</div></div></td>
437 <td><div class=
"exampleContainer expandable">
438 <div class=
"example"><pre>
443 </pre></div></div></td></tr>
447 <!---------------------------------- OS X ------------------------------------>
448 <h3 id=
"osx_checkers">OS X Checkers
</h3>
449 <table class=
"checkers">
450 <colgroup><col class=
"namedescr"><col class=
"example"></colgroup>
451 <thead><tr><td>Name, Description
</td><td>Example
</td></tr></thead>
454 <tr><td><div class=
"namedescr expandable"><span class=
"name">
455 osx.API
</span><span class=
"lang">
456 (C)
</span><div class=
"descr">
457 Check for proper uses of various Apple APIs:
<div class=functions
>
458 dispatch_once
</div></div></div></td>
459 <td><div class=
"exampleContainer expandable">
460 <div class=
"example"><pre>
462 dispatch_once_t pred =
0;
463 dispatch_once(
&pred, ^(){}); // warn: dispatch_once uses local
465 </pre></div></div></td></tr>
468 <tr><td><div class=
"namedescr expandable"><span class=
"name">
469 osx.SecKeychainAPI
</span><span class=
"lang">
470 (C)
</span><div class=
"descr">
471 Check for improper uses of the Security framework's Keychain APIs:
<div class=functions
>
472 SecKeychainItemCopyContent
<br>
473 SecKeychainFindGenericPassword
<br>
474 SecKeychainFindInternetPassword
<br>
475 SecKeychainItemFreeContent
<br>
476 SecKeychainItemCopyAttributesAndData
<br>
477 SecKeychainItemFreeAttributesAndData
</div></div></div></td>
478 <td><div class=
"exampleContainer expandable">
479 <div class=
"example"><pre>
481 unsigned int *ptr =
0;
484 SecKeychainItemFreeContent(ptr,
&length);
485 // warn: trying to free data which has not been allocated
488 <div class=
"example"><pre>
490 unsigned int *ptr =
0;
495 SecKeychainItemCopyContent(
2, ptr, ptr, length, outData);
496 // warn: data is not released
499 <div class=
"example"><pre>
501 unsigned int *ptr =
0;
506 SecKeychainItemCopyContent(
2, ptr, ptr, length,
&outData);
508 SecKeychainItemFreeContent(ptr, outData);
509 // warn: only call free if a non-NULL buffer was returned
512 <div class=
"example"><pre>
514 unsigned int *ptr =
0;
519 SecKeychainItemCopyContent(
2, ptr, ptr, length,
&outData);
521 st = SecKeychainItemCopyContent(
2, ptr, ptr, length,
&outData);
522 // warn: release data before another call to the allocator
525 SecKeychainItemFreeContent(ptr, outData);
528 <div class=
"example"><pre>
530 SecKeychainItemRef itemRef =
0;
531 SecKeychainAttributeInfo *info =
0;
532 SecItemClass *itemClass =
0;
533 SecKeychainAttributeList *attrList =
0;
538 SecKeychainItemCopyAttributesAndData(itemRef, info,
539 itemClass,
&attrList,
540 length,
&outData);
542 SecKeychainItemFreeContent(attrList, outData);
543 // warn: deallocator doesn't match the allocator
545 </pre></div></div></td></tr>
548 <tr><td><div class=
"namedescr expandable"><span class=
"name">
549 osx.cocoa.AtSync
</span><span class=
"lang">
550 (ObjC)
</span><div class=
"descr">
551 Check for nil pointers used as mutexes for
<code>@synchronized
</code>.
</div></div></td>
552 <td><div class=
"exampleContainer expandable">
553 <div class=
"example"><pre>
556 @synchronized(x) {} // warn: nil value used as mutex
559 <div class=
"example"><pre>
562 @synchronized(y) {} // warn: uninitialized value used as mutex
564 </pre></div></div></td></tr>
567 <tr><td><div class=
"namedescr expandable"><span class=
"name">
568 osx.cocoa.ClassRelease
</span><span class=
"lang">
569 (ObjC)
</span><div class=
"descr">
570 Check for sending
<code>retain
</code>,
<code>release
</code>, or
<code>
571 autorelease
</code> directly to a class.
</div></div></td>
572 <td><div class=
"exampleContainer expandable">
573 <div class=
"example"><pre>
574 @interface MyClass : NSObject
578 [MyClass release]; // warn
580 </pre></div></div></td></tr>
583 <tr><td><div class=
"namedescr expandable"><span class=
"name">
584 osx.cocoa.IncompatibleMethodTypes
</span><span class=
"lang">
585 (ObjC)
</span><div class=
"descr">
586 Check for an incompatible type signature when overriding an Objective-C method.
</div></div></td>
587 <td><div class=
"exampleContainer expandable">
588 <div class=
"example"><pre>
589 @interface MyClass1 : NSObject
593 @implementation MyClass1
594 - (int)foo { return
1; }
597 @interface MyClass2 : MyClass1
601 @implementation MyClass2
602 - (float)foo { return
1.0; } // warn
604 </pre></div></div></td></tr>
607 <tr><td><div class=
"namedescr expandable"><span class=
"name">
608 alpha.osx.cocoa.MissingSuperCall
</span><span class=
"lang">
609 (ObjC)
</span><div class=
"descr">
610 Warn about Objective-C methods that lack a necessary call to super. (Note: The
611 compiler now has a warning for methods annotated with
<code>objc_requires_super
</code>
612 attribute. The checker exists to check methods in the Cocoa frameworks
613 that haven't yet adopted this attribute.)
</div></div></td>
614 <td><div class=
"example"><pre>
615 @interface Test : UIViewController
618 - (void)viewDidLoad {} // warn
620 </pre></div></td></tr>
623 <tr><td><div class=
"namedescr expandable"><span class=
"name">
624 osx.cocoa.NSAutoreleasePool
</span><span class=
"lang">
625 (ObjC)
</span><div class=
"descr">
626 Warn for suboptimal uses of NSAutoreleasePool in Objective-C
627 GC mode (
<code>-fobjc-gc
</code> compiler option).
</div></div></td>
628 <td><div class=
"exampleContainer expandable">
629 <div class=
"example"><pre>
631 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
632 [pool release]; // warn
634 </pre></div></div></td></tr>
637 <tr><td><div class=
"namedescr expandable"><span class=
"name">
638 osx.cocoa.NSError
</span><span class=
"lang">
639 (ObjC)
</span><div class=
"descr">
640 Check usage of
<code>NSError**
</code> parameters.
</div></div></td>
641 <td><div class=
"exampleContainer expandable">
642 <div class=
"example"><pre>
643 @interface A : NSObject
644 - (void)foo:(NSError **)error;
648 - (void)foo:(NSError **)error {
649 // warn: method accepting NSError** should have a non-void
654 <div class=
"example"><pre>
655 @interface A : NSObject
656 - (BOOL)foo:(NSError **)error;
660 - (BOOL)foo:(NSError **)error {
661 *error =
0; // warn: potential null dereference
665 </pre></div></div></td></tr>
668 <tr><td><div class=
"namedescr expandable"><span class=
"name">
669 osx.cocoa.NilArg
</span><span class=
"lang">
670 (ObjC)
</span><div class=
"descr">
671 Check for prohibited nil arguments in specific Objective-C method calls:
<div class=functions
>
672 - caseInsensitiveCompare:
<br>
674 - compare:options:
<br>
675 - compare:options:range:
<br>
676 - compare:options:range:locale:
<br>
677 - componentsSeparatedByCharactersInSet:
<br>
678 - initWithFormat:
</div></div></div></td>
679 <td><div class=
"exampleContainer expandable">
680 <div class=
"example"><pre>
681 NSComparisonResult test(NSString *s) {
682 NSString *aString = nil;
683 return [s caseInsensitiveCompare:aString];
684 // warn: argument to 'NSString' method
685 // 'caseInsensitiveCompare:' cannot be nil
687 </pre></div></div></td></tr>
690 <tr><td><div class=
"namedescr expandable"><span class=
"name">
691 osx.cocoa.RetainCount
</span><span class=
"lang">
692 (ObjC)
</span><div class=
"descr">
693 Check for leaks and violations of the Cocoa Memory Management rules.
</div></div></td>
694 <td><div class=
"exampleContainer expandable">
695 <div class=
"example"><pre>
697 NSString *s = [[NSString alloc] init]; // warn
700 <div class=
"example"><pre>
701 CFStringRef test(char *bytes) {
702 return CFStringCreateWithCStringNoCopy(
703 0, bytes, NSNEXTSTEPStringEncoding,
0); // warn
705 </pre></div></div></td></tr>
708 <tr><td><div class=
"namedescr expandable"><span class=
"name">
709 osx.cocoa.SelfInit
</span><span class=
"lang">
710 (ObjC)
</span><div class=
"descr">
711 Check that
<code>self
</code> is properly initialized inside an initializer
712 method.
</div></div></td>
713 <td><div class=
"exampleContainer expandable">
714 <div class=
"example"><pre>
715 @interface MyObj : NSObject {
721 @implementation MyObj
724 x =
0; // warn: instance variable used while 'self' is not
730 <div class=
"example"><pre>
731 @interface MyObj : NSObject
735 @implementation MyObj
738 return self; // warn: returning uninitialized 'self'
741 </pre></div></div></td></tr>
744 <tr><td><div class=
"namedescr expandable"><span class=
"name">
745 osx.cocoa.UnusedIvars
</span><span class=
"lang">
746 (ObjC)
</span><div class=
"descr">
747 Warn about private ivars that are never used.
</div></div></td>
748 <td><div class=
"exampleContainer expandable">
749 <div class=
"example"><pre>
750 @interface MyObj : NSObject {
756 @implementation MyObj
758 </pre></div></div></td></tr>
761 <tr><td><div class=
"namedescr expandable"><span class=
"name">
762 osx.cocoa.VariadicMethodTypes
</span><span class=
"lang">
763 (ObjC)
</span><div class=
"descr">
764 Check for passing non-Objective-C types to variadic collection initialization
765 methods that expect only Objective-C types.
</div></div></td>
766 <td><div class=
"exampleContainer expandable">
767 <div class=
"example"><pre>
769 [NSSet setWithObjects:@
"Foo",
"Bar", nil];
770 // warn: argument should be an ObjC pointer type, not 'char *'
772 </pre></div></div></td></tr>
775 <tr><td><div class=
"namedescr expandable"><span class=
"name">
776 osx.coreFoundation.CFError
</span><span class=
"lang">
777 (C)
</span><div class=
"descr">
778 Check usage of
<code>CFErrorRef*
</code> parameters.
</div></div></td>
779 <td><div class=
"exampleContainer expandable">
780 <div class=
"example"><pre>
781 void test(CFErrorRef *error) {
782 // warn: function accepting CFErrorRef* should have a
786 <div class=
"example"><pre>
787 int foo(CFErrorRef *error) {
788 *error =
0; // warn: potential null dereference
791 </pre></div></div></td></tr>
794 <tr><td><div class=
"namedescr expandable"><span class=
"name">
795 osx.coreFoundation.CFNumber
</span><span class=
"lang">
796 (C)
</span><div class=
"descr">
797 Check for improper uses of
<code>CFNumberCreate
</code>.
</div></div></td>
798 <td><div class=
"exampleContainer expandable">
799 <div class=
"example"><pre>
800 CFNumberRef test(unsigned char x) {
801 return CFNumberCreate(
0, kCFNumberSInt16Type,
&x);
802 // warn:
8 bit integer is used to initialize a
16 bit integer
804 </pre></div></div></td></tr>
807 <tr><td><div class=
"namedescr expandable"><span class=
"name">
808 osx.coreFoundation.CFRetainRelease
</span><span class=
"lang">
809 (C)
</span><div class=
"descr">
810 Check for null arguments to
<code>CFRetain
</code>,
<code>CFRelease
</code>,
811 <code>CFMakeCollectable
</code>.
</div></div></td>
812 <td><div class=
"exampleContainer expandable">
813 <div class=
"example"><pre>
814 void test(CFTypeRef p) {
819 <div class=
"example"><pre>
820 void test(int x, CFTypeRef p) {
824 CFRelease(p); // warn
826 </pre></div></div></td></tr>
829 <tr><td><div class=
"namedescr expandable"><span class=
"name">
830 osx.coreFoundation.containers.OutOfBounds
</span><span class=
"lang">
831 (C)
</span><div class=
"descr">
832 Checks for index out-of-bounds when using
<code>CFArray
</code> API.
</div></div></td>
833 <td><div class=
"exampleContainer expandable">
834 <div class=
"example"><pre>
836 CFArrayRef A = CFArrayCreate(
0,
0,
0,
&kCFTypeArrayCallBacks);
837 CFArrayGetValueAtIndex(A,
0); // warn
839 </pre></div></div></td></tr>
842 <tr><td><div class=
"namedescr expandable"><span class=
"name">
843 osx.coreFoundation.containers.PointerSizedValues
</span><span class=
"lang">
844 (C)
</span><div class=
"descr">
845 Warns if
<code>CFArray
</code>,
<code>CFDictionary
</code>,
<code>CFSet
</code> are
846 created with non-pointer-size values.
</div></div></td>
847 <td><div class=
"exampleContainer expandable">
848 <div class=
"example"><pre>
851 CFArrayRef A = CFArrayCreate(
0, (const void **)x,
1,
852 &kCFTypeArrayCallBacks); // warn
854 </pre></div></div></td></tr>
858 <!------------------------------- security ------------------------------------>
859 <h3 id=
"security_checkers">Security Checkers
</h3>
860 <table class=
"checkers">
861 <colgroup><col class=
"namedescr"><col class=
"example"></colgroup>
862 <thead><tr><td>Name, Description
</td><td>Example
</td></tr></thead>
865 <tr><td><div class=
"namedescr expandable"><span class=
"name">
866 security.FloatLoopCounter
</span><span class=
"lang">
867 (C)
</span><div class=
"descr">
868 Warn on using a floating point value as a loop counter (CERT: FLP30-C,
869 FLP30-CPP).
</div></div></td>
870 <td><div class=
"exampleContainer expandable">
871 <div class=
"example"><pre>
873 for (float x =
0.1f; x <=
1.0f; x +=
0.1f) {} // warn
875 </pre></div></div></td></tr>
878 <tr><td><div class=
"namedescr expandable"><span class=
"name">
879 security.insecureAPI.UncheckedReturn
</span><span class=
"lang">
880 (C)
</span><div class=
"descr">
881 Warn on uses of functions whose return values must be always checked:
<div class=functions
>
887 setregid
</div></div></div></td>
888 <td><div class=
"exampleContainer expandable">
889 <div class=
"example"><pre>
893 </pre></div></div></td></tr>
896 <tr><td><div class=
"namedescr expandable"><span class=
"name">
897 security.insecureAPI.getpw
</span><span class=
"lang">
898 (C)
</span><div class=
"descr">
899 Warn on uses of the
<code>getpw
</code> function.
</div></div></td>
900 <td><div class=
"exampleContainer expandable">
901 <div class=
"example"><pre>
904 getpw(
2, buff); // warn
906 </pre></div></div></td></tr>
909 <tr><td><div class=
"namedescr expandable"><span class=
"name">
910 security.insecureAPI.gets
</span><span class=
"lang">
911 (C)
</span><div class=
"descr">
912 Warn on uses of the
<code>gets
</code> function.
</div></div></td>
913 <td><div class=
"exampleContainer expandable">
914 <div class=
"example"><pre>
919 </pre></div></div></td></tr>
922 <tr><td><div class=
"namedescr expandable"><span class=
"name">
923 security.insecureAPI.mkstemp
</span><span class=
"lang">
924 (C)
</span><div class=
"descr">
925 Warn when
<code>mktemp
</code>,
<code>mkstemp
</code>,
<code>mkstemps
</code> or
926 <code>mkdtemp
</code> is passed fewer than
6
927 X's in the format string.
</div></div></td>
928 <td><div class=
"exampleContainer expandable">
929 <div class=
"example"><pre>
931 mkstemp(
"XX"); // warn
933 </pre></div></div></td></tr>
936 <tr><td><div class=
"namedescr expandable"><span class=
"name">
937 security.insecureAPI.mktemp
</span><span class=
"lang">
938 (C)
</span><div class=
"descr">
939 Warn on uses of the
<code>mktemp
</code> function.
</div></div></td>
940 <td><div class=
"exampleContainer expandable">
941 <div class=
"example"><pre>
943 char *x = mktemp(
"/tmp/zxcv"); // warn: insecure, use mkstemp
945 </pre></div></div></td></tr>
948 <tr><td><div class=
"namedescr expandable"><span class=
"name">
949 security.insecureAPI.rand
</span><span class=
"lang">
950 (C)
</span><div class=
"descr">
951 Warn on uses of inferior random number generating functions (only if
<code>arc4random
</code>
952 function is available):
<div class=functions
>
961 rand_r
</div></div></div></td>
962 <td><div class=
"exampleContainer expandable">
963 <div class=
"example"><pre>
967 </pre></div></div></td></tr>
970 <tr><td><div class=
"namedescr expandable"><span class=
"name">
971 security.insecureAPI.strcpy
</span><span class=
"lang">
972 (C)
</span><div class=
"descr">
973 Warn on uses of the
<code>strcpy
</code> and
<code>strcat
</code> functions.
</div></div></td>
974 <td><div class=
"exampleContainer expandable">
975 <div class=
"example"><pre>
980 strcpy(x, y); // warn
982 </pre></div></div></td></tr>
985 <tr><td><div class=
"namedescr expandable"><span class=
"name">
986 security.insecureAPI.vfork
</span><span class=
"lang">
987 (C)
</span><div class=
"descr">
988 Warn on uses of the
<code>vfork
</code> function.
</div></div></td>
989 <td><div class=
"exampleContainer expandable">
990 <div class=
"example"><pre>
994 </pre></div></div></td></tr>
998 <!--------------------------------- unix -------------------------------------->
999 <h3 id=
"unix_checkers">Unix Checkers
</h3>
1000 <table class=
"checkers">
1001 <colgroup><col class=
"namedescr"><col class=
"example"></colgroup>
1002 <thead><tr><td>Name, Description
</td><td>Example
</td></tr></thead>
1005 <tr><td><div class=
"namedescr expandable"><span class=
"name">
1006 unix.API
</span><span class=
"lang">
1007 (C)
</span><div class=
"descr">
1008 Check calls to various UNIX/POSIX functions:
<div class=functions
>
1015 <td><div class=
"exampleContainer expandable">
1016 <div class=
"example"><pre>
1017 // Currently the check is performed for apple targets only.
1018 void test(const char *path) {
1019 int fd = open(path, O_CREAT);
1020 // warn: call to 'open' requires a third argument when the
1021 // 'O_CREAT' flag is set
1024 <div class=
"example"><pre>
1028 pthread_once_t pred = {
0x30B1BCBA, {
0}};
1029 pthread_once(
&pred, f);
1030 // warn: call to 'pthread_once' uses the local variable
1033 <div class=
"example"><pre>
1035 void *p = malloc(
0); // warn: allocation size of
0 bytes
1038 <div class=
"example"><pre>
1040 void *p = calloc(
0,
42); // warn: allocation size of
0 bytes
1043 <div class=
"example"><pre>
1045 void *p = malloc(
1);
1046 p = realloc(p,
0); // warn: allocation size of
0 bytes
1049 <div class=
"example"><pre>
1051 void *p = alloca(
0); // warn: allocation size of
0 bytes
1054 <div class=
"example"><pre>
1056 void *p = valloc(
0); // warn: allocation size of
0 bytes
1058 </pre></div></div></td></tr>
1061 <tr><td><div class=
"namedescr expandable"><span class=
"name">
1062 unix.Malloc
</span><span class=
"lang">
1063 (C)
</span><div class=
"descr">
1064 Check for memory leaks, double free, and use-after-free and offset problems
1065 involving
<code>malloc
</code>.
</div></div></td>
1066 <td><div class=
"exampleContainer expandable">
1067 <div class=
"example"><pre>
1071 free(p); // warn: attempt to free released memory
1074 <div class=
"example"><pre>
1076 int *p = malloc(sizeof(int));
1078 *p =
1; // warn: use after free
1081 <div class=
"example"><pre>
1085 return; // warn: memory is never released
1088 <div class=
"example"><pre>
1091 free(a); // warn: argument is not allocated by malloc
1094 <div class=
"example"><pre>
1096 int *p = malloc(sizeof(char));
1098 free(p); // warn: argument to free() is offset by -
4 bytes
1100 </pre></div></div></td></tr>
1103 <tr><td><div class=
"namedescr expandable"><span class=
"name">
1104 unix.MallocSizeof
</span><span class=
"lang">
1105 (C)
</span><div class=
"descr">
1106 Check for dubious
<code>malloc
</code>,
<code>calloc
</code> or
1107 <code>realloc
</code> arguments involving
<code>sizeof
</code>.
</div></div></td>
1108 <td><div class=
"exampleContainer expandable">
1109 <div class=
"example"><pre>
1111 long *p = malloc(sizeof(short));
1112 // warn: result is converted to 'long *', which is
1113 // incompatible with operand type 'short'
1116 </pre></div></div></td></tr>
1119 <tr><td><div class=
"namedescr expandable"><span class=
"name">
1120 unix.MismatchedDeallocator
</span><span class=
"lang">
1121 (C, C++, ObjC)
</span><div class=
"descr">
1122 Check for mismatched deallocators (e.g. passing a pointer allocating
1123 with
<code>new
</code> to
<code>free()
</code>).
</div></div></td>
1124 <td><div class=
"exampleContainer expandable">
1125 <div class=
"example"><pre>
1128 int *p = (int *)malloc(sizeof(int));
1132 <div class=
"example"><pre>
1134 void __attribute((ownership_returns(malloc))) *user_malloc(size_t);
1137 int *p = (int *)user_malloc(sizeof(int));
1141 <div class=
"example"><pre>
1148 <div class=
"example"><pre>
1151 int *p = new int[
1];
1152 realloc(p, sizeof(long)); // warn
1155 <div class=
"example"><pre>
1157 template
<typename T
>
1158 struct SimpleSmartPointer {
1161 explicit SimpleSmartPointer(T *p =
0) : ptr(p) {}
1162 ~SimpleSmartPointer() {
1168 SimpleSmartPointer
<int
> a((int *)malloc(
4));
1171 <div class=
"example"><pre>
1174 int *p = (int *)operator new(
0);
1178 <div class=
"example"><pre>
1180 void test(NSUInteger dataLength) {
1182 NSData *d = [NSData dataWithBytesNoCopy:p
1183 length:sizeof(int) freeWhenDone:
1];
1184 // warn +dataWithBytesNoCopy:length:freeWhenDone: cannot take
1185 // ownership of memory allocated by 'new'
1187 </pre></div></div></td></tr>
1190 <tr><td><div class=
"namedescr expandable"><span class=
"name">
1191 unix.cstring.BadSizeArg
</span><span class=
"lang">
1192 (C)
</span><div class=
"descr">
1193 Check the size argument passed to
<code>strncat
</code> for common erroneous
1194 patterns. Use
<code>-Wno-strncat-size
</code> compiler option to mute other
1195 <code>strncat
</code>-related compiler warnings.
1197 <td><div class=
"exampleContainer expandable">
1198 <div class=
"example"><pre>
1201 strncat(dest,
"***", sizeof(dest));
1202 // warn: potential buffer overflow
1204 </pre></div></div></td></tr>
1207 <tr><td><div class=
"namedescr expandable"><span class=
"name">
1208 unix.cstring.NullArg
</span><span class=
"lang">
1209 (C)
</span><div class=
"descr">
1210 Check for null pointers being passed as arguments to C string functions:
<div class=functions
>
1220 strncasecmp
</div></div></div></td>
1221 <td><div class=
"example"><pre>
1223 return strlen(
0); // warn
1225 </pre></div></td></tr>
1229 </div> <!-- page -->
1230 </div> <!-- content -->