ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Brian Gix <brian.gix@intel.com>
To: ell@lists.01.org
Subject: [PATCH v2] cert: Fix warning of possible uninitialized var
Date: Mon, 18 Jan 2021 10:20:28 -0800	[thread overview]
Message-ID: <20210118182028.964376-1-brian.gix@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1484 bytes --]

ell/cert-crypto.c: In function ‘cert_pkcs12_pbkdf’:
ell/cert-crypto.c:244:3: error: ‘bmpstring’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  244 |   explicit_bzero(bmpstring, passwd_len);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 ell/cert-crypto.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/ell/cert-crypto.c b/ell/cert-crypto.c
index 6eb4e14..838d5b5 100644
--- a/ell/cert-crypto.c
+++ b/ell/cert-crypto.c
@@ -198,7 +198,8 @@ uint8_t *cert_pkcs12_pbkdf(const char *password,
 	/* Documented as v(ceiling(s/v)), usually will just equal v */
 	unsigned int s_len = (salt_len + hash->v - 1) & ~(hash->v - 1);
 	/* Documented as p(ceiling(s/p)), usually will just equal v */
-	unsigned int p_len = (passwd_len + hash->v - 1) & ~(hash->v - 1);
+	unsigned int p_len = password ?
+			(passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;
 	uint8_t di[hash->v + s_len + p_len];
 	uint8_t *ptr;
 	unsigned int j;
@@ -235,10 +236,11 @@ uint8_t *cert_pkcs12_pbkdf(const char *password,
 		ptr += s_len + salt_len - j;
 	}
 
-	for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len)
-		memcpy(ptr, bmpstring, passwd_len);
-
 	if (p_len) {
+		for (j = passwd_len; j < p_len;
+					j += passwd_len, ptr += passwd_len)
+			memcpy(ptr, bmpstring, passwd_len);
+
 		memcpy(ptr, bmpstring, p_len + passwd_len - j);
 
 		explicit_bzero(bmpstring, passwd_len);
-- 
2.25.4

             reply	other threads:[~2021-01-18 18:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 18:20 Brian Gix [this message]
2021-01-22 16:15 ` [PATCH v2] cert: Fix warning of possible uninitialized var Denis Kenzior
2021-01-22 22:29   ` Andrew Zaborowski
2021-01-25 16:34 ` Denis Kenzior
2021-01-25 17:40   ` Gix, Brian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210118182028.964376-1-brian.gix@intel.com \
    --to=brian.gix@intel.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).