cert: Fix warning of possible uninitialized var
PATCH 1/1 cert: Fix warning of possible uninitialized var
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)ell/cert-crypto.c +1 -1
@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password, {/* All lengths in bytes instead of bits */ size_t passwd_len = password ?2 *strlen (password) +2 :0 ; -uint8_t *bmpstring; +uint8_t *bmpstring =NULL ;/* 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 */
Signature · 1 line
2.25.4
Hi Brian,
Quoted 4 lines · Brian Gix
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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What compiler are you seeing this on?
Quoted 9 lines
--- ell/cert-crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ell/cert-crypto.c +0
-0
ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 197
Quoted 5 lines
ell/cert-crypto.c +1
-1@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password, {/* All lengths in bytes instead of bits */ size_t passwd_len = password ?2 *strlen (password) +2 :0 ; -uint8_t *bmpstring; +uint8_t *bmpstring =NULL ;
So generally I don't like this type of fix because it just hides problems. The issues with bmpstring use seem to be a bit more complex than that.
ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 200
Quoted 4 lines
ell/cert-crypto.c +0
-0/* 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 */
Andrew:
Why is p_len initialized to be non-zero. In particular, this block:
for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len)
memcpy(ptr, bmpstring, passwd_len);would seem to copy from an uninitialized bmpstring even if password is NULL.
Regards,
-Denis
Quoted 31 lines · Denis Kenzior
Quoted 4 lines · Brian Gix
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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~What compiler are you seeing this on?
Quoted 9 lines
--- ell/cert-crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ell/cert-crypto.c +0
-0ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 197
Quoted 5 lines
ell/cert-crypto.c +1
-1@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password, {/* All lengths in bytes instead of bits */ size_t passwd_len = password ?2 *strlen (password) +2 :0 ; -uint8_t *bmpstring; +uint8_t *bmpstring =NULL ;So generally I don't like this type of fix because it just hides problems. The issues with bmpstring use seem to be a bit more complex than that.
ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 200
Quoted 4 lines
ell/cert-crypto.c +0
-0/* 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 */
Quoted 8 lines
Andrew:
Why is
p_leninitialized to be non-zero. In particular, this block:for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len) memcpy(ptr, bmpstring, passwd_len);would seem to copy from an uninitialized bmpstring even if password is NULL.
It's not very obvious but p_len and passwd_len are both going to be 0 if password is NULL. p_len becomes (v - 1) & ~(v - 1), I can see that it's hard for the compiler to notice that.
Brian, can you check if perhaps initializing p_len this way fixes it:
unsigned int p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;
Or the part that uses bmpstring can be made conditional on password as well.
Best regard
Stotland
On Thu, 2021-01-14 at 23:53 +0100, Andrew Zaborowski wrote:
On Thu, 14 Jan 2021 at 22:35, Denis Kenzior <
<mailto:[email protected]>
denkenz(a)gmail.com
Quoted 1 line
wrote:
On 1/14/21 3:16 PM, Brian Gix wrote:
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What compiler are you seeing this on?
Not sure which version of the compiler Brian is using, but I encounter this issue with:
gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
---
ell/cert-crypto.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
ell/cert-crypto.c +0 -0
index 6eb4e14..b3d3000 100644
--- a/ell/cert-crypto.c
+++ b/ell/cert-crypto.c
@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password,
{ /* All lengths in bytes instead of bits */
size_t passwd_len = password ? 2 * strlen(password) + 2 : 0;- uint8_t *bmpstring;
+ uint8_t *bmpstring = NULL;
So generally I don't like this type of fix because it just hides problems. The
issues with bmpstring use seem to be a bit more complex than that.
/* 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 */Andrew:
Why is p_len initialized to be non-zero. In particular, this block:
for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len)
memcpy(ptr, bmpstring, passwd_len);would seem to copy from an uninitialized bmpstring even if password is NULL.
It's not very obvious but p_len and passwd_len are both going to be 0
if password is NULL. p_len becomes (v - 1) & ~(v - 1), I can see that
it's hard for the compiler to notice that.
Brian, can you check if perhaps initializing p_len this way fixes it:
unsigned int p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;
This change still does not fix the compiler problem.
However, the warning disappears if we move "for" loop inside the "if" clause that immediately follows.
The way I see it, the for loop is not going to be executed if p_len is zero anyway and this chage appears to be safe since the comparisons are perfrmed on unsigned integers.
- 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);Or the part that uses bmpstring can be made conditional on password as well.
Best regard
_______________________________________________
ell mailing list --
<mailto:[email protected]>
ell(a)lists.01.org
To unsubscribe send an email to
<mailto:[email protected]>
ell-leave(a)lists.01.org
Gix
Quoted 64 lines · Inga
Quoted 11 lines · Andrew Zaborowski
On Thu, 14 Jan 2021 at 22:35, Denis Kenzior <
denkenz(a)gmail.comQuoted 9 lines
wrote:
Quoted 5 lines · Brian Gix
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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~What compiler are you seeing this on?
Not sure which version of the compiler Brian is using, but I encounter this issue with:
gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)Quoted 32 lines
Quoted 23 lines
Quoted 9 lines
--- ell/cert-crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ell/cert-crypto.c +0
-0ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 197
Quoted 5 lines
ell/cert-crypto.c +1
-1@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password, {/* All lengths in bytes instead of bits */ size_t passwd_len = password ?2 *strlen (password) +2 :0 ; -uint8_t *bmpstring; +uint8_t *bmpstring =NULL ;So generally I don't like this type of fix because it just hides problems. The issues with bmpstring use seem to be a bit more complex than that.
ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 200
Quoted 4 lines
ell/cert-crypto.c +0
-0/* 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 */ Quoted 8 lines
Andrew:
Why is
p_leninitialized to be non-zero. In particular, this block:for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len) memcpy(ptr, bmpstring, passwd_len);would seem to copy from an uninitialized bmpstring even if password is NULL.
Quoted 7 lines
It's not very obvious but
p_lenandpasswd_lenare both going to be 0 if password is NULL.p_lenbecomes (v - 1) & ~(v - 1), I can see that it's hard for the compiler to notice that.Brian, can you check if perhaps initializing
p_lenthis way fixes it:unsigned int
p_len= password ? (passwd_len+hash->v- 1) & ~(hash->v - 1) : 0;This change still does not fix the compiler problem.
However, the warning disappears if we move "for" loop inside the "if" clause that immediately follows.
The way I see it, the for loop is not going to be executed if
p_lenis zero anyway and this chage appears to be safe since the comparisons are perfrmed on unsigned integers.
Review
Quoted 7 lines
(quoted diff) +2
-2- 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);
This does *not* fix the problen on "gcc (GCC) 9.3.1 20200408" unless *combined* with the change from Andrew:
unsigned int p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;
Quoted 11 lines
Quoted 11 lines
Or the part that uses bmpstring can be made conditional on password as well.
Best regard
_______________________________________________
ell mailing list --
ell(a)lists.01.orgTo unsubscribe send an email to
ell-leave(a)lists.01.org
Stotland
On Mon, 2021-01-18 at 18:24 +0000, Gix, Brian wrote:
On Sat, 2021-01-16 at 07:28 +0000, Stotland, Inga wrote:
On Thu, 2021-01-14 at 23:53 +0100, Andrew Zaborowski wrote:
On Thu, 14 Jan 2021 at 22:35, Denis Kenzior <
<mailto:[email protected]>
denkenz(a)gmail.com
Quoted 1 line
wrote:
On 1/14/21 3:16 PM, Brian Gix wrote:
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What compiler are you seeing this on?
Not sure which version of the compiler Brian is using, but I encounter this issue with:
gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
---
ell/cert-crypto.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
ell/cert-crypto.c +0 -0
index 6eb4e14..b3d3000 100644
--- a/ell/cert-crypto.c
+++ b/ell/cert-crypto.c
@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password,
{ /* All lengths in bytes instead of bits */
size_t passwd_len = password ? 2 * strlen(password) + 2 : 0;- uint8_t *bmpstring;
+ uint8_t *bmpstring = NULL;
So generally I don't like this type of fix because it just hides problems. The
issues with bmpstring use seem to be a bit more complex than that.
/* 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 */Andrew:
Why is p_len initialized to be non-zero. In particular, this block:
for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len)
memcpy(ptr, bmpstring, passwd_len);would seem to copy from an uninitialized bmpstring even if password is NULL.
It's not very obvious but p_len and passwd_len are both going to be 0
if password is NULL. p_len becomes (v - 1) & ~(v - 1), I can see that
it's hard for the compiler to notice that.
Brian, can you check if perhaps initializing p_len this way fixes it:
unsigned int p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;
This change still does not fix the compiler problem.
However, the warning disappears if we move "for" loop inside the "if" clause that immediately follows.
The way I see it, the for loop is not going to be executed if p_len is zero anyway and this
chage appears to be safe since the comparisons are perfrmed on unsigned integers.
- 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);
This does *not* fix the problen on "gcc (GCC) 9.3.1 20200408" unless *combined* with the change from Andrew:
unsigned int p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;
True, I forgot to metion that both changes were needed.
Or the part that uses bmpstring can be made conditional on password as well.
Best regard
_______________________________________________
ell mailing list --
<mailto:[email protected]>
ell(a)lists.01.org
To unsubscribe send an email to
<mailto:[email protected]>
ell-leave(a)lists.01.org
Gix
This is an ongoing problem with us in BlueZ.
PLEASE NOTE THAT WE ARE STUCK ON VER 0.35 UNTIL RESOLVED
We have two solutions which currently work:
1. Auto-Initialize bmpstring = NULL declaration of cert_pkcs12_pbkdf()
Denis has already spoken out against this solution
2. Auto-Initialize of p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0; Move explicit_bzero of bmpstring to within the zero check of p_len "if (p_len)"
Nobody has spoken against this change, but we still seek final resolution.
I understand that once ELL is generally available for dynamic runtime linking, this won't be an issue, but for now we need to be able to build ELL from within BlueZ and cannot turn off any of the build warnings.
Quoted 90 lines · Brian
Quoted 65 lines · Inga
Quoted 12 lines · Andrew Zaborowski
On Thu, 14 Jan 2021 at 22:35, Denis Kenzior <
denkenz(a)gmail.comQuoted 10 lines
wrote:
Quoted 6 lines · Brian Gix
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); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~What compiler are you seeing this on?
Not sure which version of the compiler Brian is using, but I encounter this issue with:
gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)Quoted 32 lines
Quoted 23 lines
Quoted 9 lines
--- ell/cert-crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ell/cert-crypto.c +0
-0ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 197
Quoted 5 lines
ell/cert-crypto.c +1
-1@@ -194,7 +194,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password, {/* All lengths in bytes instead of bits */ size_t passwd_len = password ?2 *strlen (password) +2 :0 ; -uint8_t *bmpstring; +uint8_t *bmpstring =NULL ;So generally I don't like this type of fix because it just hides problems. The issues with bmpstring use seem to be a bit more complex than that.
ell/cert-crypto.c uint8_t *cert_pkcs12_pbkdf(const char *password, · line 200
Quoted 4 lines
ell/cert-crypto.c +0
-0/* 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 */ Quoted 8 lines
Andrew:
Why is
p_leninitialized to be non-zero. In particular, this block:for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len) memcpy(ptr, bmpstring, passwd_len);would seem to copy from an uninitialized bmpstring even if password is NULL.
Quoted 7 lines
It's not very obvious but
p_lenandpasswd_lenare both going to be 0 if password is NULL.p_lenbecomes (v - 1) & ~(v - 1), I can see that it's hard for the compiler to notice that.Brian, can you check if perhaps initializing
p_lenthis way fixes it:unsigned int
p_len= password ? (passwd_len+hash->v- 1) & ~(hash->v - 1) : 0;This change still does not fix the compiler problem.
However, the warning disappears if we move "for" loop inside the "if" clause that immediately follows.
The way I see it, the for loop is not going to be executed if
p_lenis zero anyway and this chage appears to be safe since the comparisons are perfrmed on unsigned integers.Review
Quoted 7 lines
(quoted diff) +2
-2- 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);This does *not* fix the problen on "gcc (GCC) 9.3.1 20200408" unless *combined* with the change from Andrew:
unsigned int p_len = password ? (passwd_len + hash->v - 1) & ~(hash->v - 1) : 0;Quoted 10 lines
Quoted 10 lines
Or the part that uses bmpstring can be made conditional on password as well.
Best regard
_______________________________________________
ell mailing list --
ell(a)lists.01.orgTo unsubscribe send an email to
ell-leave(a)lists.01.org_______________________________________________
ell mailing list -- ell(a)lists.01.org
To unsubscribe send an email to ell-leave(a)lists.01.org