From f812967fb8f33a7e6af6aa060de17a3bc97deb0c Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 14 Sep 2014 15:44:13 -0700 Subject: [PATCH] Coverage exclusion when relevant --- .../chacha20poly1305/sodium/aead_chacha20poly1305.c | 2 ++ src/libsodium/crypto_sign/ed25519/ref10/sign.c | 3 +++ .../randombytes/salsa20/randombytes_salsa20_random.c | 8 +++++--- .../randombytes/sysrandom/randombytes_sysrandom.c | 10 ++++++---- src/libsodium/sodium/core.c | 2 +- src/libsodium/sodium/runtime.c | 2 +- src/libsodium/sodium/utils.c | 6 +++--- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c b/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c index 3439cb38..945efe33 100644 --- a/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +++ b/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c @@ -37,6 +37,7 @@ crypto_aead_chacha20poly1305_encrypt(unsigned char *c, unsigned char slen[8U]; (void) nsec; +/* LCOV_EXCL_START */ #ifdef ULONG_LONG_MAX if (mlen > ULONG_LONG_MAX - crypto_aead_chacha20poly1305_ABYTES) { if (clen != NULL) { @@ -45,6 +46,7 @@ crypto_aead_chacha20poly1305_encrypt(unsigned char *c, return -1; } #endif +/* LCOV_EXCL_STOP */ crypto_stream_chacha20(block0, sizeof block0, npub, k); crypto_onetimeauth_poly1305_init(&state, block0); diff --git a/src/libsodium/crypto_sign/ed25519/ref10/sign.c b/src/libsodium/crypto_sign/ed25519/ref10/sign.c index 008b5c2a..dd6684de 100644 --- a/src/libsodium/crypto_sign/ed25519/ref10/sign.c +++ b/src/libsodium/crypto_sign/ed25519/ref10/sign.c @@ -61,6 +61,7 @@ crypto_sign(unsigned char *sm, unsigned long long *smlen, { unsigned long long siglen; +/* LCOV_EXCL_START */ if (crypto_sign_detached(sm, &siglen, m, mlen, sk) != 0 || siglen > crypto_sign_ed25519_BYTES) { if (smlen != NULL) { @@ -69,6 +70,8 @@ crypto_sign(unsigned char *sm, unsigned long long *smlen, memset(sm, 0, mlen + crypto_sign_ed25519_BYTES); return -1; } +/* LCOV_EXCL_STOP */ + memmove(sm + siglen, m, mlen); if (smlen != NULL) { *smlen = mlen + siglen; diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index 9b9c5833..1435d07e 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -112,6 +112,7 @@ safe_read(const int fd, void * const buf_, size_t count) static int randombytes_salsa20_random_random_dev_open(void) { +/* LCOV_EXCL_START */ struct stat st; static const char *devices[] = { # ifndef USE_BLOCKING_RANDOM @@ -133,6 +134,7 @@ randombytes_salsa20_random_random_dev_open(void) } while (*device != NULL); return -1; +/* LCOV_EXCL_STOP */ } static void @@ -145,7 +147,7 @@ randombytes_salsa20_random_init(void) if ((stream.random_data_source_fd = randombytes_salsa20_random_random_dev_open()) == -1) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } errno = errno_save; } @@ -183,11 +185,11 @@ randombytes_salsa20_random_stir(void) #ifndef _WIN32 if (safe_read(stream.random_data_source_fd, m0, sizeof m0) != (ssize_t) sizeof m0) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } #else /* _WIN32 */ if (! RtlGenRandom((PVOID) m0, (ULONG) sizeof m0)) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } #endif COMPILER_ASSERT(sizeof stream.key == crypto_auth_hmacsha512256_BYTES); diff --git a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c index 0ffcc2e9..4f864b5b 100644 --- a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +++ b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c @@ -102,6 +102,7 @@ safe_read(const int fd, void * const buf_, size_t count) static int randombytes_sysrandom_random_dev_open(void) { +/* LCOV_EXCL_START */ struct stat st; static const char *devices[] = { # ifndef USE_BLOCKING_RANDOM @@ -123,6 +124,7 @@ randombytes_sysrandom_random_dev_open(void) } while (*device != NULL); return -1; +/* LCOV_EXCL_STOP */ } static void @@ -132,7 +134,7 @@ randombytes_sysrandom_init(void) if ((stream.random_data_source_fd = randombytes_sysrandom_random_dev_open()) == -1) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } errno = errno_save; } @@ -203,14 +205,14 @@ randombytes_sysrandom_buf(void * const buf, const size_t size) #endif #ifndef _WIN32 if (safe_read(stream.random_data_source_fd, buf, size) != (ssize_t) size) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } #else if (size > 0xffffffff) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } if (! RtlGenRandom((PVOID) buf, (ULONG) size)) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } #endif } diff --git a/src/libsodium/sodium/core.c b/src/libsodium/sodium/core.c index 615851b1..367f2751 100644 --- a/src/libsodium/sodium/core.c +++ b/src/libsodium/sodium/core.c @@ -15,7 +15,7 @@ sodium_init(void) } sodium_runtime_get_cpu_features(); if (crypto_onetimeauth_pick_best_implementation() == NULL) { - return -1; + return -1; /* LCOV_EXCL_LINE */ } randombytes_stir(); _sodium_alloc_init(); diff --git a/src/libsodium/sodium/runtime.c b/src/libsodium/sodium/runtime.c index cdd5b597..f76ce1a8 100644 --- a/src/libsodium/sodium/runtime.c +++ b/src/libsodium/sodium/runtime.c @@ -88,7 +88,7 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features) _cpuid(cpu_info, 0x0); if ((id = cpu_info[0]) == 0U) { - return -1; + return -1; /* LCOV_EXCL_LINE */ } _cpuid(cpu_info, 0x00000001); #ifndef HAVE_EMMINTRIN_H diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index efb92638..ed088b62 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -61,7 +61,7 @@ sodium_memzero(void * const pnt, const size_t len) SecureZeroMemory(pnt, len); #elif defined(HAVE_MEMSET_S) if (memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } #elif defined(HAVE_EXPLICIT_BZERO) explicit_bzero(pnt, len); @@ -215,7 +215,7 @@ _sodium_alloc_init(void) page_size = (size_t) si.dwPageSize; #endif if (page_size < CANARY_SIZE) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } randombytes_buf(canary, sizeof canary); @@ -360,7 +360,7 @@ _sodium_malloc(const size_t size) return NULL; } if (page_size <= sizeof canary || page_size < sizeof unprotected_size) { - abort(); + abort(); /* LCOV_EXCL_LINE */ } size_with_canary = (sizeof canary) + size; unprotected_size = _page_round(size_with_canary);