diff mbox series

[v3,1/4] crypto/luks: Initialize stack variable to silence warning

Message ID 7d55ac8f0d021d39809298cac2f13f3826c284c8.1677617035.git.dxu@dxuuu.xyz
State New
Headers show
Series qga: Add optional `merge-output` flag to guest-exec QAPI | expand

Commit Message

Daniel Xu Feb. 28, 2023, 8:48 p.m. UTC
With `../configure --enable-sanitizers`, I was getting the following
build error:

        In file included from /usr/include/string.h:535,
                         from /home/dxu/dev/qemu/include/qemu/osdep.h:99,
                         from ../crypto/block-luks.c:21:
        In function ‘memset’,
            inlined from ‘qcrypto_block_luks_store_key’ at ../crypto/block-luks.c:843:9:
        /usr/include/bits/string_fortified.h:59:10: error: ‘splitkeylen’ may be used
        uninitialized [-Werror=maybe-uninitialized]
           59 |   return __builtin___memset_chk (__dest, __ch, __len,
              |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           60 |                                  __glibc_objsize0 (__dest));
              |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
        ../crypto/block-luks.c: In function ‘qcrypto_block_luks_store_key’:
        ../crypto/block-luks.c:699:12: note: ‘splitkeylen’ was declared here
          699 |     size_t splitkeylen;
              |            ^~~~~~~~~~~
        cc1: all warnings being treated as errors

The function is actually correct -- in the cleanup branch `splitkeylen`
usage is guarded by checking `splitkey` nullness. But the compiler is
not smart enough to realize that.

Fix warning by initializing the variable.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 crypto/block-luks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel P. Berrangé March 1, 2023, 8:53 a.m. UTC | #1
On Tue, Feb 28, 2023 at 01:48:01PM -0700, Daniel Xu wrote:
> With `../configure --enable-sanitizers`, I was getting the following
> build error:
> 
>         In file included from /usr/include/string.h:535,
>                          from /home/dxu/dev/qemu/include/qemu/osdep.h:99,
>                          from ../crypto/block-luks.c:21:
>         In function ‘memset’,
>             inlined from ‘qcrypto_block_luks_store_key’ at ../crypto/block-luks.c:843:9:
>         /usr/include/bits/string_fortified.h:59:10: error: ‘splitkeylen’ may be used
>         uninitialized [-Werror=maybe-uninitialized]
>            59 |   return __builtin___memset_chk (__dest, __ch, __len,
>               |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>            60 |                                  __glibc_objsize0 (__dest));
>               |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
>         ../crypto/block-luks.c: In function ‘qcrypto_block_luks_store_key’:
>         ../crypto/block-luks.c:699:12: note: ‘splitkeylen’ was declared here
>           699 |     size_t splitkeylen;
>               |            ^~~~~~~~~~~
>         cc1: all warnings being treated as errors
> 
> The function is actually correct -- in the cleanup branch `splitkeylen`
> usage is guarded by checking `splitkey` nullness. But the compiler is
> not smart enough to realize that.
> 
> Fix warning by initializing the variable.
> 
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>  crypto/block-luks.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
diff mbox series

Patch

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index 5688783ab1..bfdef25c80 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -696,7 +696,7 @@  qcrypto_block_luks_store_key(QCryptoBlock *block,
     QCryptoBlockLUKS *luks = block->opaque;
     QCryptoBlockLUKSKeySlot *slot;
     g_autofree uint8_t *splitkey = NULL;
-    size_t splitkeylen;
+    size_t splitkeylen = 0;
     g_autofree uint8_t *slotkey = NULL;
     g_autoptr(QCryptoCipher) cipher = NULL;
     g_autoptr(QCryptoIVGen) ivgen = NULL;