cert-crypto: pragma false positive (-Wmaybe-uninitialized)
James Prestwood
PATCH 1/2 cert-crypto: pragma false positive (-Wmaybe-uninitialized)
On musl-gcc 'bmpstring' was detected as maybe uninitialized. This is actually a false positive since the usage is guarded by if (p_len) but the compiler isn't aware. Pragma to ignore this warning.
ell/cert-crypto.c: In function 'cert_pkcs12_pbkdf':ell/cert-crypto.c:246:17: error: 'bmpstring' may be used uninitialized in this function [-Werror=maybe-uninitialized]
246 | explicit_bzero(bmpstring, passwd_len);
--- ell/cert-crypto.c | 3 +++ 1 file changed, 3 insertions(+)
ell/cert-crypto.c +3 -0
@@ -236,6 +236,8 @@ uint8_t *cert_pkcs12_pbkdf(const char *password, ptr += s_len + salt_len - j; } +_Pragma("GCC diagnostic push") +_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")if (p_len) {for (j = passwd_len; j < p_len; j += passwd_len, ptr += passwd_len)
@@ -246,6 +248,7 @@ uint8_t *cert_pkcs12_pbkdf(const char *password,explicit_bzero (bmpstring, passwd_len);l_free (bmpstring); } +_Pragma ("GCC diagnostic pop" ) key = l_malloc(key_len + hash->len);
Signature · 1 line
2.34.1
James Prestwood
PATCH 2/2 missing: use PTRDIFF_MAX instead of -1
On musl-gcc the compiler complains that the size passed to memchr (-1) is larger than the object size (size_t). Looking at the values its limiting size_t to a max size of a signed integer (0x7FFF....) and we are passing 0xFFFFF....
Since this size is quite large its not expected that anyone will ever need to use memchr with a buffer this big. Limiting the size to a signed integer max value should be just fine.
Instead, use PTRDIFF_MAX rather than -1. Below is the warning produced in upstream:
In file included from ell/pem.c:45:
In function 'rawmemchr',
inlined from 'pem_load_buffer' at ell/pem.c:227:21: ell/missing.h:76:16: error: 'memchr' specified bound 18446744073709551615 may exceed maximum object size 9223372036854775807 [-Werror=stringop-overread] 76 | return memchr(s, c, (size_t) -1); --- ell/missing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/missing.h +1 -1
@@ -73,7 +73,7 @@ static inline void *rawmemchr(const void *s, int c) { _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wstringop-overflow=\"") -return memchr (s, c, (size_t )-1 ); +return memchr (s, c,PTRDIFF_MAX ); _Pragma("GCC diagnostic pop") }#endif
Signature · 1 line
2.34.1
Denis Kenzior
Hi James,
Quoted 5 lines · James Prestwood
On musl-gcc 'bmpstring' was detected as maybe uninitialized. This is actually a false positive since the usage is guarded by if (
p_len) but the compiler isn't aware. Pragma to ignore this warning.
Quoted 7 lines
ell/cert-crypto.c: In function 'cert_pkcs12_pbkdf':ell/cert-crypto.c:246:17: error: 'bmpstring' may be used uninitialized in this function [-Werror=maybe-uninitialized]
246 |explicit_bzero(bmpstring, passwd_len);--- ell/cert-crypto.c | 3 +++ 1 file changed, 3 insertions(+)
Both applied, thanks.
Regards,
-Denis