From: Dorinda Bassey <dbassey@redhat.com>
To: qemu-devel@nongnu.org
Cc: aesteve@redhat.com, sgarzare@redhat.com,
marcandre.lureau@redhat.com, Dorinda Bassey <dbassey@redhat.com>
Subject: [PATCH] virtio-dmabuf: Ensure UUID persistence for hash table insertion
Date: Thu, 7 Nov 2024 13:52:01 +0100 [thread overview]
Message-ID: <20241107125201.1640759-1-dbassey@redhat.com> (raw)
In `virtio_add_resource` function, the UUID used as a key for
`g_hash_table_insert` was temporary, which could lead to
invalid lookups when accessed later. This patch ensures that
the UUID remains valid by duplicating it into a newly allocated
memory space (persistent_uuid). The value is then inserted into
the hash table with this persistent UUID key to ensure that the
key stored in the hash table remains valid as long as the hash
table entry exists.
Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
---
hw/display/virtio-dmabuf.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/display/virtio-dmabuf.c b/hw/display/virtio-dmabuf.c
index 3dba4577ca7..4353970bc87 100644
--- a/hw/display/virtio-dmabuf.c
+++ b/hw/display/virtio-dmabuf.c
@@ -39,7 +39,12 @@ static bool virtio_add_resource(QemuUUID *uuid, VirtioSharedObject *value)
g_free);
}
if (g_hash_table_lookup(resource_uuids, uuid) == NULL) {
- g_hash_table_insert(resource_uuids, uuid, value);
+ QemuUUID *persistent_uuid = g_memdup2(uuid, sizeof(QemuUUID));
+ if (persistent_uuid == NULL) {
+ result = false;
+ } else {
+ g_hash_table_insert(resource_uuids, persistent_uuid, value);
+ }
} else {
result = false;
}
--
2.47.0
next reply other threads:[~2024-11-07 12:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 12:52 Dorinda Bassey [this message]
2024-11-07 13:24 ` [PATCH] virtio-dmabuf: Ensure UUID persistence for hash table insertion Albert Esteve
2024-11-07 13:43 ` Stefano Garzarella
2024-11-07 13:47 ` Stefano Garzarella
2024-11-07 17:37 ` Dorinda Bassey
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=20241107125201.1640759-1-dbassey@redhat.com \
--to=dbassey@redhat.com \
--cc=aesteve@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.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).