All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <michael.roth@amd.com>,
	Fabiano Rosas <farosas@suse.de>,
	Konstantin Kostiuk <kkostiuk@redhat.com>
Subject: Re: [PATCH 2/3] tests: Use qemu_mkdir_with_parents() for all test code
Date: Mon, 16 Dec 2024 18:35:57 +0000	[thread overview]
Message-ID: <Z2BzDSM74jFYOglT@redhat.com> (raw)
In-Reply-To: <20241216161413.1644171-3-peterx@redhat.com>

On Mon, Dec 16, 2024 at 11:14:12AM -0500, Peter Xu wrote:
> Coverity isn't happy on the QEMU test cases where g_mkdir_with_parents() is
> used without checking retvals.  Use qemu_mkdir_with_parents() to fix them.
> 
> Resolves: Coverity CID 1568381
> Resolves: Coverity CID 1568378
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  tests/qtest/migration/tls-tests.c     | 6 +++---
>  tests/unit/test-crypto-tlscredsx509.c | 4 ++--
>  tests/unit/test-crypto-tlssession.c   | 6 +++---
>  tests/unit/test-io-channel-tls.c      | 6 +++---
>  4 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/qtest/migration/tls-tests.c b/tests/qtest/migration/tls-tests.c
> index 5704a1f992..c78daff998 100644
> --- a/tests/qtest/migration/tls-tests.c
> +++ b/tests/qtest/migration/tls-tests.c
> @@ -43,14 +43,14 @@ migrate_hook_start_tls_psk_common(QTestState *from,
>      data->workdir = g_strdup_printf("%s/tlscredspsk0", tmpfs);
>      data->pskfile = g_strdup_printf("%s/%s", data->workdir,
>                                      QCRYPTO_TLS_CREDS_PSKFILE);
> -    g_mkdir_with_parents(data->workdir, 0700);
> +    qemu_mkdir_with_parents(data->workdir, 0700);

I dislike this as a solution as it is not obvious that qemu_mkdir_with_parents
is any different. IMHO the right solution for tests is to assert inline

  g_asset(g_mkdir_with_parents(...) == 0);

>      test_tls_psk_init(data->pskfile);
>  
>      if (mismatch) {
>          data->workdiralt = g_strdup_printf("%s/tlscredspskalt0", tmpfs);
>          data->pskfilealt = g_strdup_printf("%s/%s", data->workdiralt,
>                                             QCRYPTO_TLS_CREDS_PSKFILE);
> -        g_mkdir_with_parents(data->workdiralt, 0700);
> +        qemu_mkdir_with_parents(data->workdiralt, 0700);
>          test_tls_psk_init_alt(data->pskfilealt);
>      }
>  
> @@ -152,7 +152,7 @@ migrate_hook_start_tls_x509_common(QTestState *from,
>          data->clientcert = g_strdup_printf("%s/client-cert.pem", data->workdir);
>      }
>  
> -    g_mkdir_with_parents(data->workdir, 0700);
> +    qemu_mkdir_with_parents(data->workdir, 0700);
>  
>      test_tls_init(data->keyfile);
>  #ifndef _WIN32
> diff --git a/tests/unit/test-crypto-tlscredsx509.c b/tests/unit/test-crypto-tlscredsx509.c
> index 3c25d75ca1..57ce0134df 100644
> --- a/tests/unit/test-crypto-tlscredsx509.c
> +++ b/tests/unit/test-crypto-tlscredsx509.c
> @@ -75,7 +75,7 @@ static void test_tls_creds(const void *opaque)
>      QCryptoTLSCreds *creds;
>  
>  #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
> -    g_mkdir_with_parents(CERT_DIR, 0700);
> +    qemu_mkdir_with_parents(CERT_DIR, 0700);
>  
>      unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      if (data->isServer) {
> @@ -141,7 +141,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>  
> -    g_mkdir_with_parents(WORKDIR, 0700);
> +    qemu_mkdir_with_parents(WORKDIR, 0700);
>  
>      test_tls_init(KEYFILE);
>  
> diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-tlssession.c
> index 3395f73560..db97cbefe7 100644
> --- a/tests/unit/test-crypto-tlssession.c
> +++ b/tests/unit/test-crypto-tlssession.c
> @@ -271,8 +271,8 @@ static void test_crypto_tls_session_x509(const void *opaque)
>  
>  #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/"
>  #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/"
> -    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> -    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
> +    qemu_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> +    qemu_mkdir_with_parents(SERVER_CERT_DIR, 0700);
>  
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
> @@ -420,7 +420,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>  
> -    g_mkdir_with_parents(WORKDIR, 0700);
> +    qemu_mkdir_with_parents(WORKDIR, 0700);
>  
>      test_tls_init(KEYFILE);
>      test_tls_psk_init(PSKFILE);
> diff --git a/tests/unit/test-io-channel-tls.c b/tests/unit/test-io-channel-tls.c
> index e036ac5df4..6cb83e891a 100644
> --- a/tests/unit/test-io-channel-tls.c
> +++ b/tests/unit/test-io-channel-tls.c
> @@ -125,8 +125,8 @@ static void test_io_channel_tls(const void *opaque)
>  
>  #define CLIENT_CERT_DIR "tests/test-io-channel-tls-client/"
>  #define SERVER_CERT_DIR "tests/test-io-channel-tls-server/"
> -    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> -    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
> +    qemu_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> +    qemu_mkdir_with_parents(SERVER_CERT_DIR, 0700);
>  
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
> @@ -273,7 +273,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>  
> -    g_mkdir_with_parents(WORKDIR, 0700);
> +    qemu_mkdir_with_parents(WORKDIR, 0700);
>  
>      test_tls_init(KEYFILE);
>  
> -- 
> 2.47.0
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  parent reply	other threads:[~2024-12-16 18:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16 16:14 [PATCH 0/3] tests: Fix some new coverity issues reported Peter Xu
2024-12-16 16:14 ` [PATCH 1/3] osdep: Add qemu_mkdir_with_parents() Peter Xu
2024-12-16 16:56   ` Peter Maydell
2024-12-16 17:12     ` Peter Xu
2024-12-16 17:28       ` Konstantin Kostiuk
2024-12-16 17:54         ` Peter Xu
2024-12-16 18:34     ` Daniel P. Berrangé
2024-12-16 17:16   ` Alex Bennée
2024-12-16 16:14 ` [PATCH 2/3] tests: Use qemu_mkdir_with_parents() for all test code Peter Xu
2024-12-16 17:16   ` Alex Bennée
2024-12-16 18:35   ` Daniel P. Berrangé [this message]
2024-12-16 16:14 ` [PATCH 3/3] tests/migration: Drop arch_[source|target] Peter Xu
2024-12-16 17:15   ` Alex Bennée

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=Z2BzDSM74jFYOglT@redhat.com \
    --to=berrange@redhat.com \
    --cc=farosas@suse.de \
    --cc=kkostiuk@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.