* [PATCH for-5.0] qga: Fix undefined C behavior
@ 2020-03-20 15:05 Eric Blake
0 siblings, 0 replies; only message in thread
From: Eric Blake @ 2020-03-20 15:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Michael Roth
The QAPI struct GuestFileWhence has a comment about how we are
exploiting equivalent values between two different integer types
shared in a union. But C says behavior is undefined on assignments to
overlapping storage when the two types are not the same width, and
indeed, 'int64_t value' and 'enum QGASeek name' are very likely to be
different in width. Utilize a temporary variable to fix things.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: 0b4b49387
Fixes: Coverity CID 1421990
Signed-off-by: Eric Blake <eblake@redhat.com>
---
qga/commands.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/qga/commands.c b/qga/commands.c
index f8852beb9ca4..4471a9f08d38 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -482,10 +482,15 @@ done:
* the guest's SEEK_ constants. */
int ga_parse_whence(GuestFileWhence *whence, Error **errp)
{
- /* Exploit the fact that we picked values to match QGA_SEEK_*. */
+ /*
+ * Exploit the fact that we picked values to match QGA_SEEK_*;
+ * however, we have to use a temporary variable since the union
+ * members may have different size.
+ */
if (whence->type == QTYPE_QSTRING) {
+ int value = whence->u.name;
whence->type = QTYPE_QNUM;
- whence->u.value = whence->u.name;
+ whence->u.value = value;
}
switch (whence->u.value) {
case QGA_SEEK_SET:
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-20 15:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-20 15:05 [PATCH for-5.0] qga: Fix undefined C behavior Eric Blake
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).