qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Christian Schoenebeck <qemu_oss@crudebyte.com>
Subject: [PATCH] tests: virtio-9p-client: Rreaddir fields are all mandatory
Date: Thu, 27 Apr 2023 15:10:23 +0200	[thread overview]
Message-ID: <20230427131023.105801-1-pbonzini@redhat.com> (raw)

If rreaddir.entries is NULL, the resulting dirent list is leaked.
Check that the rreaddir case is filled correctly in the caller
when treaddir succeeds; this then makes it possible to remove
the conditionals is v9fs_rreaddir.

Reported by Coverity.

Cc: Christian Schoenebeck <qemu_oss@crudebyte.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/qtest/libqos/virtio-9p-client.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/virtio-9p-client.c
index e4a368e03660..17125e78deae 100644
--- a/tests/qtest/libqos/virtio-9p-client.c
+++ b/tests/qtest/libqos/virtio-9p-client.c
@@ -579,6 +579,7 @@ TReadDirRes v9fs_treaddir(TReadDirOpt opt)
             v9fs_rlerror(req, &err);
             g_assert_cmpint(err, ==, opt.expectErr);
         } else {
+            g_assert(opt.rreaddir.count && opt.rreaddir.nentries && opt.rreaddir.entries);
             v9fs_rreaddir(req, opt.rreaddir.count, opt.rreaddir.nentries,
                           opt.rreaddir.entries);
         }
@@ -600,9 +601,7 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
     v9fs_req_recv(req, P9_RREADDIR);
     v9fs_uint32_read(req, &local_count);
 
-    if (count) {
-        *count = local_count;
-    }
+    *count = local_count;
 
     for (int32_t togo = (int32_t)local_count;
          togo >= 13 + 8 + 1 + 2;
@@ -610,9 +609,7 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
     {
         if (!e) {
             e = g_new(struct V9fsDirent, 1);
-            if (entries) {
-                *entries = e;
-            }
+            *entries = e;
         } else {
             e = e->next = g_new(struct V9fsDirent, 1);
         }
@@ -624,10 +621,7 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
         v9fs_string_read(req, &slen, &e->name);
     }
 
-    if (nentries) {
-        *nentries = n;
-    }
-
+    *nentries = n;
     v9fs_req_free(req);
 }
 
-- 
2.40.0



             reply	other threads:[~2023-04-27 13:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27 13:10 Paolo Bonzini [this message]
2023-04-28 12:51 ` [PATCH] tests: virtio-9p-client: Rreaddir fields are all mandatory Christian Schoenebeck

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=20230427131023.105801-1-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).