ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] cert: Fix warning of possible uninitialized var
@ 2021-01-18 18:20 Brian Gix
  2021-01-22 16:15 ` Denis Kenzior
  2021-01-25 16:34 ` Denis Kenzior
  0 siblings, 2 replies; 5+ messages in thread
From: Brian Gix @ 2021-01-18 18:20 UTC (permalink / raw)
  To: ell

[-- 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-25 17:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 18:20 [PATCH v2] cert: Fix warning of possible uninitialized var Brian Gix
2021-01-22 16:15 ` Denis Kenzior
2021-01-22 22:29   ` Andrew Zaborowski
2021-01-25 16:34 ` Denis Kenzior
2021-01-25 17:40   ` Gix, Brian

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).