Hi Niels, The attached patches add a static analyzer run in the nettle CI and fix few minor issues found with it.
There two issues I didn't fix because I am not sure whether it is a logical error or an initialization of the variables in question could solve it. I attach the html output of scan-view. Both involve the ecc_mod() function and the variable 'hi'. regards, Nikos
From 283da8ece01938da0bbf279050870cb017cd704f Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Tue, 16 May 2017 15:25:28 +0200 Subject: [PATCH 4/4] hogweed-benchmark: eliminated memory leak Signed-off-by: Nikos Mavrogiannopoulos <[email protected]> --- examples/hogweed-benchmark.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/hogweed-benchmark.c b/examples/hogweed-benchmark.c index 3fabe20..ebce903 100644 --- a/examples/hogweed-benchmark.c +++ b/examples/hogweed-benchmark.c @@ -612,7 +612,10 @@ bench_openssl_ecdsa_init (unsigned size) /* This curve isn't supported in this build of openssl */ if (ctx->key == NULL) - return NULL; + { + free(ctx); + return NULL; + } if (!EC_KEY_generate_key( ctx->key)) die ("Openssl EC_KEY_generate_key failed.\n"); -- 2.9.3
From 2567f86986addc4b3f0851f83d32916a73fbce10 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Tue, 16 May 2017 15:23:07 +0200 Subject: [PATCH 3/4] _aes_set_key: ensure with assert() that nk is non-zero Signed-off-by: Nikos Mavrogiannopoulos <[email protected]> --- aes-set-key-internal.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aes-set-key-internal.c b/aes-set-key-internal.c index 9b515bf..88728d8 100644 --- a/aes-set-key-internal.c +++ b/aes-set-key-internal.c @@ -39,6 +39,7 @@ #endif #include "aes-internal.h" +#include <assert.h> #include "macros.h" void @@ -52,6 +53,7 @@ _aes_set_key(unsigned nr, unsigned nk, unsigned lastkey, i; uint32_t t; + assert(nk != 0); lastkey = (AES_BLOCK_SIZE/4) * (nr + 1); for (i=0, rp = rcon; i<nk; i++) -- 2.9.3
From f21dc55795606ec95698a01f46a59d3f88af9b21 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Tue, 16 May 2017 15:21:36 +0200 Subject: [PATCH 2/4] ecc_mod_inv: eliminated dead increment Signed-off-by: Nikos Mavrogiannopoulos <[email protected]> --- ecc-mod-inv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecc-mod-inv.c b/ecc-mod-inv.c index f65c9da..6741ff0 100644 --- a/ecc-mod-inv.c +++ b/ecc-mod-inv.c @@ -144,7 +144,7 @@ ecc_mod_inv (const struct ecc_modulo *m, cnd_swap (swap, up, vp, n); cy = cnd_sub_n (odd, up, vp, n); - cy -= cnd_add_n (cy, up, m->m, n); + cnd_add_n (cy, up, m->m, n); cy = mpn_rshift (ap, ap, n, 1); assert (cy == 0); -- 2.9.3
From 92efa75f0f5fe0d077cc6adffb9874fc5780410c Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Tue, 16 May 2017 15:12:06 +0200 Subject: [PATCH 1/4] .gitlab-ci.yml: added static analyzers run Signed-off-by: Nikos Mavrogiannopoulos <[email protected]> --- .gitlab-ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6fa9898..ad6c24f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,9 @@ image: centos:7 +variables: + BUILD_IMAGES_PROJECT: gnutls/build-images + FEDORA_BUILD: buildenv-f25 + before_script: - yum install -y git make autoconf libtool automake gettext-devel glibc-devel gcc valgrind libasan-static libgcc.i686 glibc-devel.i686 @@ -55,3 +59,20 @@ Build and Check with asan: - shared except: - tags +Build with static-analyzers: + image: fedora:25 + script: + - yum install -y gmp-devel clang compiler-rt cppcheck clang-analyzer + - ./.bootstrap + - scan-build ./configure --disable-documentation + - scan-build --status-bugs -o scan-build-lib make -j$(nproc) + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - scan-build-lib/* + -- 2.9.3
<<< text/html; name="report-92919c.html"; charset="UTF-8": Unrecognized >>>
Title: ecc-mod.c
Bug Summary
| File: | ecc-mod.c |
| Location: | line 110, column 12 |
| Description: | Function call argument is an uninitialized value |
Annotated Source Code
| 1 | /* ecc-mod.c | |||||
| 2 | ||||||
| 3 | Copyright (C) 2013 Niels Möller | |||||
| 4 | ||||||
| 5 | This file is part of GNU Nettle. | |||||
| 6 | ||||||
| 7 | GNU Nettle is free software: you can redistribute it and/or | |||||
| 8 | modify it under the terms of either: | |||||
| 9 | ||||||
| 10 | * the GNU Lesser General Public License as published by the Free | |||||
| 11 | Software Foundation; either version 3 of the License, or (at your | |||||
| 12 | option) any later version. | |||||
| 13 | ||||||
| 14 | or | |||||
| 15 | ||||||
| 16 | * the GNU General Public License as published by the Free | |||||
| 17 | Software Foundation; either version 2 of the License, or (at your | |||||
| 18 | option) any later version. | |||||
| 19 | ||||||
| 20 | or both in parallel, as here. | |||||
| 21 | ||||||
| 22 | GNU Nettle is distributed in the hope that it will be useful, | |||||
| 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
| 25 | General Public License for more details. | |||||
| 26 | ||||||
| 27 | You should have received copies of the GNU General Public License and | |||||
| 28 | the GNU Lesser General Public License along with this program. If | |||||
| 29 | not, see http://www.gnu.org/licenses/. | |||||
| 30 | */ | |||||
| 31 | ||||||
| 32 | /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */ | |||||
| 33 | ||||||
| 34 | #if HAVE_CONFIG_H1 | |||||
| 35 | # include "config.h" | |||||
| 36 | #endif | |||||
| 37 | ||||||
| 38 | #include <assert.h> | |||||
| 39 | ||||||
| 40 | #include "ecc-internal.h" | |||||
| 41 | ||||||
| 42 | /* Computes r mod m, input 2*m->size, output m->size. */ | |||||
| 43 | void | |||||
| 44 | ecc_mod_nettle_ecc_mod (const struct ecc_modulo *m, mp_limb_t *rp) | |||||
| 45 | { | |||||
| 46 | mp_limb_t hi; | |||||
| ||||||
| 47 | mp_size_t mn = m->size; | |||||
| 48 | mp_size_t bn = m->B_size; | |||||
| 49 | mp_size_t sn = mn - bn; | |||||
| 50 | mp_size_t rn = 2*mn; | |||||
| 51 | mp_size_t i; | |||||
| 52 | unsigned shift; | |||||
| 53 | ||||||
| 54 | assert (sn > 0)((sn > 0) ? (void) (0) : __assert_fail ("sn > 0", "ecc-mod.c" , 54, __PRETTY_FUNCTION__)); | |||||
| 55 | ||||||
| 56 | /* FIXME: Could use mpn_addmul_2. */ | |||||
| 57 | /* Eliminate sn limbs at a time */ | |||||
| 58 | if (m->B[bn-1] < ((mp_limb_t) 1 << (GMP_NUMB_BITS(64 - 0) - 1))) | |||||
| 59 | { | |||||
| 60 | /* Multiply sn + 1 limbs at a time, so we get a mn+1 limb | |||||
| 61 | product. Then we can absorb the carry in the high limb */ | |||||
| 62 | while (rn > 2 * mn - bn) | |||||
| 63 | { | |||||
| 64 | rn -= sn; | |||||
| 65 | ||||||
| 66 | for (i = 0; i <= sn; i++) | |||||
| 67 | rp[rn+i-1] = mpn_addmul_1__gmpn_addmul_1 (rp + rn - mn - 1 + i, m->B, bn, rp[rn+i-1]); | |||||
| 68 | rp[rn-1] = rp[rn+sn-1] | |||||
| 69 | + mpn_add_n__gmpn_add_n (rp + rn - sn - 1, rp + rn - sn - 1, rp + rn - 1, sn); | |||||
| 70 | } | |||||
| 71 | goto final_limbs; | |||||
| 72 | } | |||||
| 73 | else | |||||
| 74 | { | |||||
| 75 | while (rn >= 2 * mn - bn) | |||||
| 76 | { | |||||
| 77 | rn -= sn; | |||||
| 78 | ||||||
| 79 | for (i = 0; i < sn; i++) | |||||
| 80 | rp[rn+i] = mpn_addmul_1__gmpn_addmul_1 (rp + rn - mn + i, m->B, bn, rp[rn+i]); | |||||
| 81 | ||||||
| 82 | hi = mpn_add_n__gmpn_add_n (rp + rn - sn, rp + rn - sn, rp + rn, sn); | |||||
| 83 | hi = cnd_add_n (hi, rp + rn - mn, m->B, mn)__gmpn_cnd_add_n ((hi), (rp + rn - mn), (rp + rn - mn), (m-> B), (mn)); | |||||
| 84 | assert (hi == 0)((hi == 0) ? (void) (0) : __assert_fail ("hi == 0", "ecc-mod.c" , 84, __PRETTY_FUNCTION__)); | |||||
| 85 | } | |||||
| 86 | } | |||||
| 87 | ||||||
| 88 | if (rn > mn) | |||||
| 89 | { | |||||
| 90 | final_limbs: | |||||
| 91 | sn = rn - mn; | |||||
| 92 | ||||||
| 93 | for (i = 0; i < sn; i++) | |||||
| 94 | rp[mn+i] = mpn_addmul_1__gmpn_addmul_1 (rp + i, m->B, bn, rp[mn+i]); | |||||
| 95 | ||||||
| 96 | hi = mpn_add_n__gmpn_add_n (rp + bn, rp + bn, rp + mn, sn); | |||||
| 97 | hi = sec_add_1_nettle_sec_add_1 (rp + bn + sn, rp + bn + sn, mn - bn - sn, hi); | |||||
| 98 | } | |||||
| 99 | ||||||
| 100 | shift = m->size * GMP_NUMB_BITS(64 - 0) - m->bit_size; | |||||
| 101 | if (shift > 0) | |||||
| 102 | { | |||||
| 103 | /* Combine hi with top bits, add in */ | |||||
| 104 | hi = (hi << shift) | (rp[mn-1] >> (GMP_NUMB_BITS(64 - 0) - shift)); | |||||
| 105 | rp[mn-1] = (rp[mn-1] & (((mp_limb_t) 1 << (GMP_NUMB_BITS(64 - 0) - shift)) - 1)) | |||||
| 106 | + mpn_addmul_1__gmpn_addmul_1 (rp, m->B_shifted, mn-1, hi); | |||||
| 107 | } | |||||
| 108 | else | |||||
| 109 | { | |||||
| 110 | hi = cnd_add_n (hi, rp, m->B_shifted, mn)__gmpn_cnd_add_n ((hi), (rp), (rp), (m->B_shifted), (mn)); | |||||
| ||||||
| 111 | assert (hi == 0)((hi == 0) ? (void) (0) : __assert_fail ("hi == 0", "ecc-mod.c" , 111, __PRETTY_FUNCTION__)); | |||||
| 112 | } | |||||
| 113 | } |
_______________________________________________ nettle-bugs mailing list [email protected] http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs
