X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=crypto%2Fmem_clr.c;h=1a06636d0ce8da052d0dec9580362274208084fb;hb=b77390a2ff1d8c707ea5aad4bd30cedbccedee5b;hp=0b72966cfa1b480edb675d095e7458b17b887423;hpb=df29cc8f77bcf09cdd245feeaea452f5f91e4125;p=openssl.git diff --git a/crypto/mem_clr.c b/crypto/mem_clr.c index 0b72966cfa..1a06636d0c 100644 --- a/crypto/mem_clr.c +++ b/crypto/mem_clr.c @@ -1,6 +1,7 @@ /* crypto/mem_clr.c -*- mode:C; c-file-style: "eay" -*- */ -/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL - * project 2002. +/* + * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project + * 2002. */ /* ==================================================================== * Copyright (c) 2001 The OpenSSL Project. All rights reserved. @@ -10,7 +11,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -62,14 +63,19 @@ unsigned char cleanse_ctr = 0; void OPENSSL_cleanse(void *ptr, size_t len) - { - unsigned char *p = ptr; - size_t loop = len; - while(loop--) - { - *(p++) = cleanse_ctr; - cleanse_ctr += (17 + (((unsigned char *)&p)[sizeof(unsigned char *)-1] & 0xF)); - } - if(memchr(ptr, cleanse_ctr, len)) - cleanse_ctr += 63; - } +{ + unsigned char *p = ptr; + size_t loop = len, ctr = cleanse_ctr; + + if (ptr == NULL) + return; + + while (loop--) { + *(p++) = (unsigned char)ctr; + ctr += (17 + ((size_t)p & 0xF)); + } + p = memchr(ptr, (unsigned char)ctr, len); + if (p) + ctr += (63 + (size_t)p); + cleanse_ctr = (unsigned char)ctr; +}