From: Eric Blake Date: Fri, 20 Mar 2020 15:05:07 +0000 (-0500) Subject: qga: Fix undefined C behavior X-Git-Tag: v4.2.1~95 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e3531619f1431f029c2d09238f404bee0d3e9091;p=thirdparty%2Fqemu.git qga: Fix undefined C behavior 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 Fixes: 0b4b49387 Fixes: Coverity CID 1421990 Signed-off-by: Eric Blake Signed-off-by: Michael Roth (cherry picked from commit a23f38a72921fa915536a981a4f8a9134512f120) Signed-off-by: Michael Roth --- diff --git a/qga/commands.c b/qga/commands.c index 0c7d1385c23..8ec7fa3c04b 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: