DevComputaria / GuiaSegurancaParaDevs

:notebook: Guia de segurança para DevComputeiros
MIT License
3 stars 0 forks source link

CERT® C Coding Standard, Second Edition, The: 98 Rules for Developing Safe, Reliable, and Secure Systems, 2nd Edition #3

Open marcialwushu opened 3 years ago

marcialwushu commented 3 years ago

By Robert C. Seacord Published Apr 14, 2014 by Addison-Wesley Professional. Part of the SEI Series in Software Engineering series. Book Sorry, this book is no longer in print. Not for Sale eBook (Watermarked) Your Price: $38.39 List Price: $47.99 Includes EPUB, MOBI, and PDF

marcialwushu commented 3 years ago

<div id="bss0f8fc8f7-6d8d-4816-9b68-458cbd7149e6" class-"bss-container"="" class="bss-container clearfix on" style="display: block;">

Sample Content

                    <h3>
                            Excerpt
                    </h3>
                        <p>
                            <a href="https://www.informit.com/articles/article.aspx?p=2182067">
                                Preface to The CERT® C Coding Standard, second edition
                            </a>
                        </p>
                    <h3>Sample Pages</h3>
    <p></p><p><a href="/content/images/9780321984043/samplepages/9780321984043_Seacord_sample.pdf">Download the sample pages</a> (includes Chapters 3, 7, and 13)</p> <p></p>
        <h3>Table of Contents</h3>
    <p><i>  </i></p><p><i>Preface xiii<br>Acknowledgments xxxvii<br>Contributors xxxix<br>About the Author xliii</i></p><i>  </i><p><i></i>&nbsp;</p>  <p><b>Chapter 1: Preprocessor (PRE) 1<br></b>PRE30-C. Do not create a universal character name through concatenation 2<br>PRE31-C. Avoid side effects in arguments to unsafe macros 3<br>PRE32-C. Do not use preprocessor directives in invocations of function-like macros 8</p>    <p><b>Chapter 2: Declarations and Initialization (DCL) 11<br></b>DCL30-C. Declare objects with appropriate storage durations 12<br>DCL31-C. Declare identifiers before using them 16<br>DCL36-C. Do not declare an identifier with conflicting linkage classifications 20<br>DCL37-C. Do not declare or define a reserved identifier 23<br>DCL38-C. Use the correct syntax when declaring a flexible array member 29<br>DCL39-C. Avoid information leakage in structure padding 32<br>DCL40-C. Do not create incompatible declarations of the same function or object 37<br>DCL41-C. Do not declare variables inside a switch statement before the first case label 43</p>    <p><b>Chapter 3: Expressions (EXP) 47<br></b>EXP30-C. Do not depend on the order of evaluation for side effects 48<br>EXP32-C. Do not access a volatile object through a nonvolatile reference 54<br>EXP33-C. Do not read uninitialized memory 56<br>EXP34-C. Do not dereference null pointers 65<br>EXP35-C. Do not modify objects with temporary lifetime 70<br>EXP36-C. Do not cast pointers into more strictly aligned pointer types 73<br>EXP37-C. Call functions with the correct number and type of arguments 77<br>EXP39-C. Do not access a variable through a pointer of an incompatible type 83<br>EXP40-C. Do not modify constant objects 89<br>EXP42-C. Do not compare padding data 91<br>EXP43-C. Avoid undefined behavior when using restrict-qualified pointers 93<br>EXP44-C. Do not rely on side effects in operands to sizeof, _Alignof, or _Generic 102<br>EXP45-C. Do not perform assignments in selection statements 105</p>    <p><b>Chapter 4: Integers (INT) 111<br></b>INT30-C. Ensure that unsigned integer operations do not wrap 112<br>INT31-C. Ensure that integer conversions do not result in lost or misinterpreted data 118<br>INT32-C. Ensure that operations on signed integers do not result in overflow 126<br>INT33-C. Ensure that division and remainder operations do not result in divide-by-zero errors 135<br>INT34-C. Do not shift an expression by a negative number of bits or by greater than or equal to the number of bits that exist in the operand 138<br>INT35-C. Use correct integer precisions 143<br>INT36-C. Converting a pointer to integer or integer to pointer 145</p>    <p><b>Chapter 5: Floating Point (FLP) 151<br></b>FLP30-C. Do not use floating-point variables as loop counters 152<br>FLP32-C. Prevent or detect domain and range errors in math functions 154<br>FLP34-C. Ensure that floating-point conversions are within range of the new type 163<br>FLP36-C. Preserve precision when converting integral values to floating-point type 166</p>    <p><b>Chapter 6: Arrays (ARR) 169<br></b>ARR30-C. Do not form or use out-of-bounds pointers or array subscripts 170<br>ARR32-C. Ensure size arguments for variable length arrays are in a valid range 180<br>ARR36-C. Do not subtract or compare two pointers that do not refer to the same array 182<br>ARR37-C. Do not add or subtract an integer to a pointer to a non-array object 184<br>ARR38-C. Guarantee that library functions do not form invalid pointers 187<br>ARR39-C. Do not add or subtract a scaled integer to a pointer 196</p>    <p><b>Chapter 7: Characters and Strings (STR) 201<br></b>STR30-C. Do not attempt to modify string literals 202<br>STR31-C. Guarantee that storage for strings has sufficient space for character data and the null terminator 205<br>STR32-C. Do not pass a non-null-terminated character sequence to a library function that expects a string 218<br>STR34-C. Cast characters to unsigned char before converting to larger integer sizes 223<br>STR37-C. Arguments to character handling functions must be representable as an unsigned char 227<br>STR38-C. Do not confuse narrow and wide character strings and functions 229</p>    <p><b>Chapter 8: Memory Management (MEM) 233<br></b>MEM30-C. Do not access freed memory 234<br>MEM31-C. Free dynamically allocated memory when no longer needed 239<br>MEM33-C. Allocate and copy structures containing a flexible array member dynamically 241<br>MEM34-C. Only free memory allocated dynamically 246<br>MEM35-C. Allocate sufficient memory for an object 250<br>MEM36-C. Do not modify the alignment of objects by calling realloc() 253</p>    <p><b>Chapter 9: Input/Output (FIO) 257<br></b>FIO30-C. Exclude user input from format strings 258<br>FIO31-C. Do not open a file that is already open 263<br>FIO32-C. Do not perform operations on devices that are only appropriate for files 265<br>FIO34-C. Distinguish between characters read from a file and EOF or WEOF 272<br>FIO37-C. Do not assume that fgets() or fgetws() returns a nonempty string when successful 277<br>FIO38-C. Do not copy a FILE object 279<br>FIO39-C. Do not alternately input and output from a stream without an intervening flush or positioning call 280<br>FIO40-C. Reset strings on fgets() or fgetws() failure 283<br>FIO41-C. Do not call getc(), putc(), getwc(), or putwc() with a stream argument that has side effects 284<br>FIO42-C. Close files when they are no longer needed 288<br>FIO44-C. Only use values for fsetpos() that are returned from fgetpos() 292<br>FIO45-C. Avoid TOCTOU race conditions while accessing files 294<br>FIO46-C. Do not access a closed file 298<br>FIO47-C. Use valid format strings 299</p>    <p><b>Chapter 10: Environment (ENV) 305<br></b>ENV30-C. Do not modify the object referenced by the return value of certain functions 306<br>ENV31-C. Do not rely on an environment pointer following an operation that may invalidate it 311<br>ENV32-C. All exit handlers must return normally 315<br>ENV33-C. Do not call system() 319<br>ENV34-C. Do not store pointers returned by certain functions 325</p>    <p><b>Chapter 11: Signals (SIG) 333<br></b>SIG30-C. Call only asynchronous-safe functions within signal handlers 334<br>SIG31-C. Do not access shared objects in signal handlers 342<br>SIG34-C. Do not call signal() from within interruptible signal handlers 345<br>SIG35-C. Do not return from a computational exception signal handler 349</p>    <p><b>Chapter 12: Error Handling (ERR) 353<br></b>ERR30-C. Set errno to zero before calling a library function known to set errno, and check errno only after the function returns a value indicating failure 354<br>ERR32-C. Do not rely on indeterminate values of errno 361<br>ERR33-C. Detect and handle standard library errors 365</p>    <p><b>Chapter 13: Concurrency (CON) 383<br></b>CON30-C. Clean up thread-specific storage 384<br>CON31-C. Do not destroy a mutex while it is locked 388<br>CON32-C. Prevent data races when accessing bit-fields from multiple threads 391<br>CON33-C. Avoid race conditions when using library functions 394<br>CON34-C. Declare objects shared between threads with appropriate storage durations 398<br>CON35-C. Avoid deadlock by locking in a predefined order 406<br>CON36-C. Wrap functions that can spuriously wake up in a loop 411<br>CON37-C. Do not call signal() in a multithreaded program 414<br>CON38-C. Preserve thread-safety and liveness when using condition variables 416<br>CON39-C. Do not join or detach a thread that was previously joined or detached 424<br>CON40-C. Do not refer to an atomic variable twice in an expression 426<br>CON41-C. Wrap functions that can fail spuriously in a loop 430</p>    <p><b>Chapter 14: Miscellaneous (MSC) 435<br></b>MSC30-C. Do not use the rand() function for generating pseudorandom numbers 436<br>MSC32-C. Properly seed pseudorandom number generators 439<br>MSC33-C. Do not pass invalid data to the asctime() function 443<br>MSC37-C. Ensure that control never reaches the end of a non-void function 446<br>MSC38-C. Do not treat a predefined identifier as an object if it might only be implemented as a macro 449<br>MSC39-C. Do not call va_arg() on a va_list that has an indeterminate value 451<br>MSC40-C. Do not violate constraints 453</p>  <b>  <p>Appendix A: Glossary 459<br></p>    <p>Appendix B: Undefined Behavior 465</p>  <p><br>Appendix C: Unspecified Behavior 481</p>  </b><p><b></b><i>&nbsp;</i></p><i>  <p>Bibliography 487<br>Index 495</p></i><p></p>
                    <a href="#productBSS" class="ss-icon tab-accordion-content-return"></a>
    </div>
marcialwushu commented 3 years ago

https://www.informit.com/store/cert-c-coding-standard-second-edition-98-rules-for-9780321984043?w_ptgrevartcl=Preface+to+The+CERT%c2%ae+C+Coding+Standard%2c+second+edition_2182067