Secure Coding mailing list archives
secure integer library
From: rcs at cert.org (Robert C. Seacord)
Date: Thu, 17 Aug 2006 10:04:21 -0400
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at: http://www.cert.org/secure-coding/ The purpose of this library is to provide a collection of utility functions that can assist software developers in writing C programs that are free from common integer problems such as integer overflow, integer truncation, and sign errors that are a common source of software vulnerabilities. Functions have been provided for all integer operations subject to overflow such as addition, subtraction, multiplication, division, unary negation, etc.) for int, long, long long, and size_t integers. The following example illustrates how the library can be used to add two signed long integer values: long retsl, xsl, ysl; xsl = LONG_MAX; ysl = 0; retsl = addsl(xsl,ysl); For short integer types (char and short) it is necessary to truncate the result of the addition using one of the safe conversion functions provided, for example: char retsc, xsc, ysc; xsc = SCHAR_MAX; ysc = 0; retsc = si2sc(addsi(xsc, ysc)); For error handling, the secure integer library uses the mechanism for Runtime-constraint handling defined by TR 24731 "Specification for Safer, More Secure C Library Functions" available at: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1135.pdf The implementation uses the high performance algorithms defined by Henry S. Warren in the book "Hacker's Delight". For more information on vulnerabilities and other problems resulting from the incorrect use of integers in C and C++ please read Chapter 5 of "Secure Coding in C and C++" which is available as a free download from the CERT web site: http://www.cert.org/books/secure-coding/moreinfo.html Please address any defect reports, comments and suggestions concerning the Secure Integer Library or CERT Secure Coding Initiative to me. Thanks to Henry and to Juan Alvarado who coded the implementation. Thanks, rCs -- Robert C. Seacord Senior Vulnerability Analyst CERT/CC Work: 412-268-7608 FAX: 412-268-6989
Current thread:
- Web Services vs. Minimizing Attack Surface John Wilander (Aug 15)
- Web Services vs. Minimizing Attack Surface Gunnar Peterson (Aug 15)
- Web Services vs. Minimizing Attack Surface Nash (Aug 15)
- <Possible follow-ups>
- Web Services vs. Minimizing Attack Surface Holger.Peine at iese.fraunhofer.de (Aug 15)
- Web Services vs. Minimizing Attack Surface Gadi Evron (Aug 15)
- Web Services vs. Minimizing Attack Surface John Wilander (Aug 16)
- Web Services vs. Minimizing Attack Surface mikeiscool (Aug 16)
- Web Services vs. Minimizing Attack Surface Gadi Evron (Aug 16)
- Web Services vs. Minimizing Attack Surface Gunnar Peterson (Aug 16)
- secure integer library Robert C. Seacord (Aug 17)
- secure integer library Pascal Meunier (Aug 17)
- secure integer library Robert C. Seacord (Aug 17)