From 58a3bca8d7a9b90ef950cba025217e3d58f81e61 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Tue, 29 Oct 2013 23:08:43 +0100 Subject: [PATCH] replaces old bzero() with memset(). --- TODO | 1 - configure | 6 ++---- configure.ac | 2 -- libpcp/config.h.in | 3 --- libpcp/key.c | 8 ++++---- libpcp/mac.c | 4 ++-- libpcp/mem.c | 2 +- libpcp/vault.c | 4 ++-- libpcp/z85.c | 2 +- tests/invalidkeys.c | 2 +- 10 files changed, 13 insertions(+), 21 deletions(-) diff --git a/TODO b/TODO index 4ffbdbb..f3d69a8 100644 --- a/TODO +++ b/TODO @@ -1,2 +1 @@ - always save vault to tmp, then validate it and copy if ok -- replace sys/endian.h by portable / configure \ No newline at end of file diff --git a/configure b/configure index 44081ed..d55d39b 100755 --- a/configure +++ b/configure @@ -12306,7 +12306,8 @@ $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi for ac_header in errno.h err.h stdlib.h string.h unistd.h stdio.h getopt.h\ - limits.h stddef.h stdint.h sys/types.h sys/stat.h endian.h sys/endian.h termios.h + limits.h stddef.h stdint.h sys/types.h sys/stat.h endian.h \ + sys/endian.h termios.h arpa/inet.h netinet/in.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -12335,7 +12336,6 @@ fi # Checks for library functions. for ac_func in \ arc4random_buf \ - bzero \ fread \ fopen \ free \ @@ -12558,8 +12558,6 @@ fi if test -n "$_ldlib"; then export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${_ldlib}" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: LD_LIBRARY_PATH: $LD_LIBRARY_PATH" >&5 -$as_echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking is libsodium compiled correctly" >&5 diff --git a/configure.ac b/configure.ac index 5064dc2..63d5e44 100755 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,6 @@ AC_TYPE_SIZE_T # Checks for library functions. AC_CHECK_FUNCS( \ arc4random_buf \ - bzero \ fread \ fopen \ free \ @@ -172,7 +171,6 @@ AC_CHECK_LIB(sodium, sodium_init, , [AC_MSG_ERROR([cannot link with -lsodium, in if test -n "$_ldlib"; then export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${_ldlib}" - AC_MSG_RESULT([LD_LIBRARY_PATH: $LD_LIBRARY_PATH]) fi AC_MSG_CHECKING([is libsodium compiled correctly]) diff --git a/libpcp/config.h.in b/libpcp/config.h.in index 245e50f..20c5966 100644 --- a/libpcp/config.h.in +++ b/libpcp/config.h.in @@ -9,9 +9,6 @@ /* Define to 1 if you have the `be32toh' function. */ #undef HAVE_BE32TOH -/* Define to 1 if you have the `bzero' function. */ -#undef HAVE_BZERO - /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H diff --git a/libpcp/key.c b/libpcp/key.c index 6904b58..d090ec1 100644 --- a/libpcp/key.c +++ b/libpcp/key.c @@ -52,7 +52,7 @@ pcp_key_t *pcpkey_encrypt(pcp_key_t *key, char *passphrase) { es = pcp_sodium_mac(&encrypted, key->secret, 32, key->nonce, encryptkey); - bzero(encryptkey, 32); + memset(encryptkey, 0, 32); free(encryptkey); if(es == 48) { @@ -77,7 +77,7 @@ pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase) { es = pcp_sodium_verify_mac(&decrypted, key->encrypted, 48, key->nonce, encryptkey); - bzero(encryptkey, 32); + memset(encryptkey, 0, 32); free(encryptkey); if(es == 0) { @@ -140,7 +140,7 @@ void pcp_cleanhashes() { pcp_key_t *current_key, *tmp; HASH_ITER(hh, pcpkey_hash, current_key, tmp) { HASH_DEL(pcpkey_hash,current_key); - bzero(current_key, sizeof(pcp_key_t)); + memset(current_key, 0, sizeof(pcp_key_t)); free(current_key); // FIXME: coredumps here after n-th secret keys has been added } } @@ -149,7 +149,7 @@ void pcp_cleanhashes() { pcp_pubkey_t *current_pub, *ptmp; HASH_ITER(hh, pcppubkey_hash, current_pub, ptmp) { HASH_DEL(pcppubkey_hash,current_pub); - bzero(current_pub, sizeof(pcp_pubkey_t)); + memset(current_pub, 0, sizeof(pcp_pubkey_t)); free(current_pub); } } diff --git a/libpcp/mac.c b/libpcp/mac.c index 9858000..6cc4067 100644 --- a/libpcp/mac.c +++ b/libpcp/mac.c @@ -34,8 +34,8 @@ unsigned char *pcp_derivekey(char *passphrase) { memcpy(key, xor, crypto_secretbox_KEYBYTES); - bzero(passphrase, plen); - bzero(temp, crypto_hash_BYTES); + memset(passphrase, 0, plen); + memset(temp, 0, crypto_hash_BYTES); free(passphrase); free(temp); free(xor); diff --git a/libpcp/mem.c b/libpcp/mem.c index a339813..3fa8f75 100644 --- a/libpcp/mem.c +++ b/libpcp/mem.c @@ -11,7 +11,7 @@ void *ucmalloc(size_t s) { exit(-1); } - bzero (value, size); + memset (value, 0, size); //printf("allocated %d bytes at %p\n", (int)size, value); diff --git a/libpcp/vault.c b/libpcp/vault.c index 2f08719..d3b5c4d 100644 --- a/libpcp/vault.c +++ b/libpcp/vault.c @@ -124,7 +124,7 @@ int pcpvault_additem(vault_t *vault, void *item, size_t itemsize, uint8_t type, fwrite(header, sizeof(vault_item_header_t), 1, vault->fd); fwrite(saveitem, itemsize, 1, vault->fd); - bzero(saveitem, itemsize); + memset(saveitem, 0, itemsize); free(saveitem); if(do_hash == 1) { @@ -223,7 +223,7 @@ unsigned char *pcpvault_create_checksum(vault_t *vault) { crypto_hash_sha256(checksum, data, datasize); - bzero(data, datasize); + memset(data, 0, datasize); free(data); return checksum; diff --git a/libpcp/z85.c b/libpcp/z85.c index 165fb81..631b91f 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -11,7 +11,7 @@ unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen) { dst = (unsigned char*)ucmalloc(outlen); dst[0] = zerolen; // add the number of zeros we add memcpy(&dst[1], src, srclen); // add the original - bzero(&dst[srclen+1], zerolen); // pad with zeroes + memset(&dst[srclen+1], 0, zerolen); // pad with zeroes *dstlen = outlen; diff --git a/tests/invalidkeys.c b/tests/invalidkeys.c index fda019b..0033a23 100644 --- a/tests/invalidkeys.c +++ b/tests/invalidkeys.c @@ -50,7 +50,7 @@ void mkinvv(const char *name, int type) { header->fileid = PCP_VAULT_ID; header->version = PCP_VAULT_VERSION; - bzero(header->checksum, 32); + memset(header->checksum, 0, 32); item->version = PCP_KEY_VERSION; item->type = PCP_KEY_TYPE_SECRET;