Download C Secure Coding Guidelines Review Draft WG14

Transcript
REVIEW DRAFT SUBJECT TO CHANGE
Contents
Error! Reference source not found.
Page
C Secure Coding Guidelines ............................................................................................................................. 1
Review Draft ........................................................................................................................................................ 1
1
Scope ...................................................................................................................................................... 1
2
2.1
Conformance ......................................................................................................................................... 1
Completeness and Soundness ............................................................................................................ 2
3
Normative references ............................................................................................................................ 2
4
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
Terms and definitions ........................................................................................................................... 3
analyzer .................................................................................................................................................. 3
asynchronous-safe ................................................................................................................................ 3
exploit ..................................................................................................................................................... 3
invalid pointer ........................................................................................................................................ 3
security flaw ........................................................................................................................................... 3
security policy ....................................................................................................................................... 3
valid pointer ........................................................................................................................................... 3
vulnerability ........................................................................................................................................... 4
5
Symbols (and abbreviated terms) ........................................................................................................ 4
6
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.12
6.13
6.14
6.15
6.16
6.17
6.18
6.19
6.20
Known Security Problems .................................................................................................................... 4
Do not call system if you do not need a command processor [ENV004] ........................................ 4
Do not use user input in format strings [FIO030] .............................................................................. 5
Detect and handle input and output errors [FIO004] ......................................................................... 5
Canonicalize file names originating from untrusted sources [FIO002] ........................................... 7
Only use valid format strings [FIO000] ............................................................................................... 8
Allocate sufficient memory for an object [MEM035] .......................................................................... 9
Do not access freed memory [MEM030] ........................................................................................... 10
Overwrite sensitive information from the heap before returning it [MEM003].............................. 11
Do not use deprecated or obsolescent functions [MSC034] .......................................................... 12
Do not truncate a null-terminated byte string [STR003] .................................................................. 15
Do not use pointer arithmetic that results in an invalid pointer [ARR038] ................................... 16
Do not loop beyond the end of an array [ARR035] .......................................................................... 17
Do not copy data into an object of insufficient storage size [ARR033] ......................................... 17
Use array indices that are within the range of the array bounds [ARR030] .................................. 18
Do not apply the sizeof operator to a pointer when taking the size of an array [ARR001] .......... 18
Evaluate integer expressions in a larger size before using with that size [INT035] ..................... 19
Do not let operations on signed integers result in overflow [INT032] ........................................... 20
Do not let integer conversions result in lost data or sign [INT031] ............................................... 21
Verify that all integer values are in range [INT008] .......................................................................... 22
Enforce limits on integer values originating from untrusted sources [INT004] ........................... 23
7
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
7.10
7.11
7.12
7.13
Direct Result ........................................................................................................................................ 24
Do not create a universal character name through concatenation [PRE030] ............................... 24
Do not shift a negative number of bits or more bits than exist in the operand [INT034] ............. 24
Use the correct syntax for flexible array members [MEM033] ........................................................ 25
Do not call remove on an open file [FIO008] .................................................................................... 26
Do not use non-standard mode parameters when calling fopen [FIO011] .................................... 26
Do not push back anything other than one read character [FIO013] ............................................. 27
Do not simultaneously open the same file multiple times [FIO031] .............................................. 28
Use feof and ferror to detect file conditions when sizeof(int) == sizeof(char) [FIO035] .............. 28
Do not use a copy of a FILE object for input and output [FIO038] ................................................. 29
Do not input and output from a stream without a flush or positioning call [FIO039]................... 29
Only use values for fsetpos that are returned from fgetpos [FIO044] ........................................... 30
Use consistent array notation across all source files [ARR031] .................................................... 31
Do not manipulate time_t typed values directly [MSC005] ............................................................. 32
Error! Reference source not found.
Copyright 2009 Carnegie Mellon University iii