aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/mem.c
Commit message (Collapse)AuthorAgeFilesLines
* Removed ugly size_t less than zero check.Hikar2017-02-211-1/+1
| | | | | | | | CLA: trivial. Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2674)
* Fix symbol shadowRichard Levitte2017-02-171-4/+4
| | | | Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2663)
* Fix "failure rate" bugsRich Salz2017-01-131-5/+6
| | | | Reviewed-by: Emilia Käsper <emilia@openssl.org> (Merged from https://github.com/openssl/openssl/pull/2228)
* Add "random malloc failure" toolingRich Salz2017-01-121-0/+89
| | | | | | | | | | | | | | | | | | | | Still needs to be documented, somehow/somewhere. The env var OPENSSL_MALLOC_FAILURES controls how often malloc/realloc should fail. It's a set of fields separated by semicolons. Each field is a count and optional percentage (separated by @) which defaults to 100. If count is zero then it lasts "forever." For example: 100;@25 means the first 100 allocations pass, then the rest have a 25% chance of failing until the program exits or crashes. If env var OPENSSL_MALLOC_FD parses as a positive integer, a record of all malloc "shouldfail" tests is written to that file descriptor. If a malloc will fail, and OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE is not set (platform specific), then a backtrace will be written to the descriptor when a malloc fails. This can be useful because a malloc may fail but not be checked, and problems will only occur later. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/1252)
* Convert memset calls to OPENSSL_cleanseMatt Caswell2016-06-301-1/+1
| | | | | | | | Ensure things really do get cleared when we intend them to. Addresses an OCAP Audit issue. Reviewed-by: Andy Polyakov <appro@openssl.org>
* Copyright consolidation 06/10Rich Salz2016-05-171-54/+6
| | | | Reviewed-by: Richard Levitte <levitte@openssl.org>
* Fix CRYPTO_clear_realloc() bug.Dr. Stephen Henson2016-04-211-2/+3
| | | | | | | | | | If allocation in CRYPTO_clear_realloc() fails don't free up the original buffer: this is consistent with the behaviour of realloc(3) and is expected in other places in OpenSSL. Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
* Build fix: remove cleanse_ctrRich Salz2016-02-251-12/+0
| | | | Reviewed-by: Andy Polyakov <appro@openssl.org>
* Remove unused parameters from internal functionsRich Salz2016-02-221-5/+2
| | | | Reviewed-by: Richard Levitte <levitte@openssl.org>
* Implement the use of heap manipulator implementionsRichard Levitte2016-02-171-34/+31
| | | | | | | | | | | | | | | | - Make use of the functions given through CRYPTO_set_mem_functions(). - CRYPTO_free(), CRYPTO_clear_free() and CRYPTO_secure_free() now receive __FILE__ and __LINE__. - The API for CRYPTO_set_mem_functions() and CRYPTO_get_mem_functions() is slightly changed, the implementation for free() now takes a couple of extra arguments, taking __FILE__ and __LINE__. - The CRYPTO_ memory functions will *always* receive __FILE__ and __LINE__ from the corresponding OPENSSL_ macros, regardless of if crypto-mdebug has been enabled or not. The reason is that if someone swaps out the malloc(), realloc() and free() implementations, we can't know if they will use them or not. Reviewed-by: Rich Salz <rsalz@openssl.org>
* Remove /* foo.c */ commentsRich Salz2016-01-261-1/+0
| | | | | | | | | | | | This was done by the following find . -name '*.[ch]' | /tmp/pl where /tmp/pl is the following three-line script: print unless $. == 1 && m@/\* .*\.[ch] \*/@; close ARGV if eof; # Close file to reset $. And then some hand-editing of other files. Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
* Enable/disable crypto-mdebug just like other featuresViktor Dukhovni2016-01-111-5/+5
| | | | | | Also always abort() on leak failure. Reviewed-by: Stephen Henson <steve@openssl.org>
* mem functions cleanupRich Salz2016-01-071-240/+96
| | | | | | | | | | | | | | | | | Only two macros CRYPTO_MDEBUG and CRYPTO_MDEBUG_ABORT to control this. If CRYPTO_MDEBUG is not set, #ifdef out the whole debug machinery. (Thanks to Jakob Bohm for the suggestion!) Make the "change wrapper functions" be the only paradigm. Wrote documentation! Format the 'set func' functions so their paramlists are legible. Format some multi-line comments. Remove ability to get/set the "memory debug" functions at runtme. Remove MemCheck_* and CRYPTO_malloc_debug_init macros. Add CRYPTO_mem_debug(int flag) function. Add test/memleaktest. Rename CRYPTO_malloc_init to OPENSSL_malloc_init; remove needless calls. Reviewed-by: Richard Levitte <levitte@openssl.org>
* Rename *_realloc_clean to *_clear_reallocRich Salz2015-12-221-1/+1
| | | | | | | Just like *_clear_free routines. Previously undocumented, used a half-dozen times within OpenSSL source. Reviewed-by: Richard Levitte <levitte@openssl.org>
* Also change the non-debug versions to use size_tKurt Roeckx2015-12-221-2/+2
| | | | | Reviewed-by: Richard Levitte <levitte@openssl.org> MR: #1518
* Modify the lower level memory allocation routines to take size_tRichard Levitte2015-12-171-14/+14
| | | | | | We've been using int for the size for a long time, it's about time... Reviewed-by: Rich Salz <rsalz@openssl.org>
* mem-cleanup, cont'd.Rich Salz2015-12-161-22/+0
| | | | | | | Remove LEVITTE_DEBUG_MEM. Remove {OPENSSL,CRYPTO}_remalloc. Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
* Rename some BUF_xxx to OPENSSL_xxxRich Salz2015-12-161-9/+0
| | | | | | | | | Rename BUF_{strdup,strlcat,strlcpy,memdup,strndup,strnlen} to OPENSSL_{strdup,strlcat,strlcpy,memdup,strndup,strnlen} Add #define's for the old names. Add CRYPTO_{memdup,strndup}, called by OPENSSL_{memdup,strndup} macros. Reviewed-by: Tim Hudson <tjh@openssl.org>
* Add and use OPENSSL_zallocRich Salz2015-09-021-4/+11
| | | | | | | | | There are many places (nearly 50) where we malloc and then memset. Add an OPENSSL_zalloc routine to encapsulate that. (Missed one conversion; thanks Richard) Also fixes GH328 Reviewed-by: Richard Levitte <levitte@openssl.org>
* Remove _locked memory functions.Rich Salz2015-08-261-119/+0
| | | | | | Undocumented, unused, unnecessary (replaced by secure arena). Reviewed-by: Richard Levitte <levitte@openssl.org>
* More secure storage of key material.Rich Salz2015-06-231-1/+72
| | | | | | | | | Add secure heap for storage of private keys (when possible). Add BIO_s_secmem(), CBIGNUM, etc. Add BIO_CTX_secure_new so all BIGNUM's in the context are secure. Contributed by Akamai Technologies under the Corporate CLA. Reviewed-by: Richard Levitte <levitte@openssl.org>
* Identify and move common internal libcrypto header filesRichard Levitte2015-05-141-1/+1
| | | | | | | | | | | | | There are header files in crypto/ that are used by a number of crypto/ submodules. Move those to crypto/include/internal and adapt the affected source code and Makefiles. The header files that got moved are: crypto/cryptolib.h crypto/md32_common.h Reviewed-by: Rich Salz <rsalz@openssl.org>
* free null cleanup finaleRich Salz2015-05-011-2/+1
| | | | | | Don't check for NULL before calling OPENSSL_free Reviewed-by: Richard Levitte <levitte@openssl.org>
* free cleanup almost the finaleRich Salz2015-04-301-2/+10
| | | | | | | | | | Add OPENSSL_clear_free which merges cleanse and free. (Names was picked to be similar to BN_clear_free, etc.) Removed OPENSSL_freeFunc macro. Fixed the small simple ones that are left: CRYPTO_free CRYPTO_free_locked OPENSSL_free_locked Reviewed-by: Richard Levitte <levitte@openssl.org>
* remove malloc castsRich Salz2015-04-281-1/+1
| | | | | | | Following ANSI C rules, remove the casts from calls to OPENSSL_malloc and OPENSSL_realloc. Reviewed-by: Richard Levitte <levitte@openssl.org>
* Fix CRYPTO_strdupLoganaden Velvindron2015-04-221-0/+3
| | | | | | | | | | | | | | The function CRYPTO_strdup (aka OPENSSL_strdup) fails to check the return value from CRYPTO_malloc to see if it is NULL before attempting to use it. This patch adds a NULL check. RT3786 Signed-off-by: Matt Caswell <matt@openssl.org> (cherry picked from commit 37b0cf936744d9edb99b5dd82cae78a7eac6ad60) Reviewed-by: Rich Salz <rsalz@openssl.org> (cherry picked from commit 20d21389c8b6f5b754573ffb6a4dc4f3986f2ca4)
* Run util/openssl-format-source -v -c .Matt Caswell2015-01-221-303/+342
| | | | Reviewed-by: Tim Hudson <tjh@openssl.org>
* Fix datarace reported by valgrind/helgrindRussell Coker2014-11-101-4/+8
| | | | | | | | | | | This doesn't really fix the datarace but changes it so it can only happens once. This isn't really a problem since we always just set it to the same value. We now just stop writing it after the first time. PR3584, https://bugs.debian.org/534534 Signed-off-by: Kurt Roeckx <kurt@roeckx.be> Reviewed-by: Rich Salz <rsalz@openssl.org>
* Version skew reduction: trivia (I hope).Ben Laurie2012-06-031-3/+1
|
* Check for potentially exploitable overflows in asn1_d2i_read_bioDr. Stephen Henson2012-04-191-0/+4
| | | | | | | | BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer in CRYPTO_realloc_clean. Thanks to Tavis Ormandy, Google Security Team, for discovering this issue and to Adam Langley <agl@chromium.org> for fixing it. (CVE-2012-2110)
* No need to disable leak checking for FIPS builds now we use internalDr. Stephen Henson2011-04-121-1/+1
| | | | memory callbacks.
* Add additional OPENSSL_init() handling add dummy call to (hopefully)Dr. Stephen Henson2011-04-011-0/+3
| | | | ensure OPENSSL_init() is always linked into an application.
* Move locking and thread ID functions into new files lock.c and thr_id.c,Dr. Stephen Henson2011-01-271-1/+1
| | | | redirect locking to minimal FIPS_lock() function where required.
* Revert the size_t modifications from HEAD that had led to moreGeoff Thorpe2008-11-121-15/+15
| | | | | | knock-on work than expected - they've been extracted into a patch series that can be completed elsewhere, or in a different branch, before merging back to HEAD.
* Fix prototypes.Dr. Stephen Henson2008-11-021-2/+2
|
* size_tification.Ben Laurie2008-11-011-13/+13
|
* Add JPAKE.Ben Laurie2008-10-261-0/+7
|
* Profiling revealed that OPENSSL_cleanse consumes *more* CPU time thanAndy Polyakov2007-05-141-2/+8
| | | | | sha1_block_data_order when hashing short messages. Move OPENSSL_cleanse to "cpuid" assembler module and gain 2x.
* CRYPTO_malloc(), CRYPTO_realloc() and variants of them should return NULLRichard Levitte2003-12-011-4/+4
| | | | | | if the give size is 0. This is a thought that came up in PR 751.
* In realloc, don't destroy the old memory area if a new one couldn't beRichard Levitte2003-10-071-3/+7
| | | | | allocated. Notified by Daniel Lucq <daniel@lucq.org>
* Make sure the memory allocation routines check for negative sizesRichard Levitte2003-02-191-0/+10
|
* Cleanse memory using the new OPENSSL_cleanse() function.Richard Levitte2002-11-281-1/+1
| | | | I've covered all the memset()s I felt safe modifying, but may have missed some.
* Add OPENSSL_cleanse() to help cleanse memory and avoid certain compilerRichard Levitte2002-11-271-0/+14
| | | | | and linker optimizations. PR: 343
* Security fixes brought forward from 0.9.7.Ben Laurie2002-11-131-2/+23
|
* If CRYPTO_realloc() is called with a NULL pointer, have it callRichard Levitte2002-08-011-0/+3
| | | | | OPENSSL_malloc(). PR: 187
* No functional change, but slightly improved code clarity.Bodo Möller2001-01-101-3/+6
|
* After discussion with Richard, change the new API for extended memoryBodo Möller2001-01-101-56/+51
| | | | | | allocation callbacks so that it is no longer visible to applications that these live at a different call level than conventional memory allocation callbacks.
* make indentation consistentBodo Möller2001-01-101-14/+14
|
* As response to a user request to be able to use external memoryRichard Levitte2001-01-101-5/+84
| | | | | | handling routines that need file name and line number information, I've added a call level to our memory handling routines to allow that kind of hooking.
* Constification of the data of a hash table. This means the callbackRichard Levitte2000-12-131-10/+10
| | | | | | | functions need to be constified, and therefore meant a number of easy changes a little everywhere. Now, if someone could explain to me why OBJ_dup() cheats...