diff mbox series

[2/3] tests: Use qemu_mkdir_with_parents() for all test code

Message ID 20241216161413.1644171-3-peterx@redhat.com (mailing list archive)
State New
Headers show
Series tests: Fix some new coverity issues reported | expand

Commit Message

Peter Xu Dec. 16, 2024, 4:14 p.m. UTC
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(-)

Comments

Alex Bennée Dec. 16, 2024, 5:16 p.m. UTC | #1
Peter Xu <peterx@redhat.com> writes:

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

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Daniel P. Berrangé Dec. 16, 2024, 6:35 p.m. UTC | #2
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
diff mbox series

Patch

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