qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Gerd Hoffmann" <kraxel@redhat.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field
Date: Fri,  3 May 2019 08:59:49 +0200	[thread overview]
Message-ID: <20190503065954.17069-3-kraxel@redhat.com> (raw)
In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com>

From: Daniel P. Berrangé <berrange@redhat.com>

The ObjectInfo struct's "filename" field is following a uint8_t
field in a packed struct and thus has bad alignment for a 16-bit
field. Switch the field to to uint8_t and use the helper function
for accessing unaligned 16-bit data.

Note that although the MTP spec specifies big endian, when transported
over the USB protocol, data is little endian.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20190415154503.6758-4-berrange@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/dev-mtp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 6b7d1296e430..963449ec7de8 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -226,7 +226,7 @@ typedef struct {
     uint32_t assoc_desc;
     uint32_t seq_no; /*unused*/
     uint8_t length; /*part of filename field*/
-    uint16_t filename[0];
+    uint8_t filename[0]; /* UTF-16 encoded */
     char date_created[0]; /*unused*/
     char date_modified[0]; /*unused*/
     char keywords[0]; /*unused*/
@@ -1551,7 +1551,7 @@ static void usb_mtp_cancel_packet(USBDevice *dev, USBPacket *p)
     fprintf(stderr, "%s\n", __func__);
 }
 
-static char *utf16_to_str(uint8_t len, uint16_t *arr)
+static char *utf16_to_str(uint8_t len, uint8_t *str16)
 {
     wchar_t *wstr = g_new0(wchar_t, len + 1);
     int count, dlen;
@@ -1559,7 +1559,7 @@ static char *utf16_to_str(uint8_t len, uint16_t *arr)
 
     for (count = 0; count < len; count++) {
         /* FIXME: not working for surrogate pairs */
-        wstr[count] = (wchar_t)arr[count];
+        wstr[count] = lduw_le_p(str16 + (count * 2));
     }
     wstr[count] = 0;
 
-- 
2.18.1

WARNING: multiple messages have this Message-ID (diff)
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>
Subject: [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field
Date: Fri,  3 May 2019 08:59:49 +0200	[thread overview]
Message-ID: <20190503065954.17069-3-kraxel@redhat.com> (raw)
Message-ID: <20190503065949.sJLIrsMxn8Owj4Q3JhTtOABFeFdm2buyV6kCZFuHFis@z> (raw)
In-Reply-To: <20190503065954.17069-1-kraxel@redhat.com>

From: Daniel P. Berrangé <berrange@redhat.com>

The ObjectInfo struct's "filename" field is following a uint8_t
field in a packed struct and thus has bad alignment for a 16-bit
field. Switch the field to to uint8_t and use the helper function
for accessing unaligned 16-bit data.

Note that although the MTP spec specifies big endian, when transported
over the USB protocol, data is little endian.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20190415154503.6758-4-berrange@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/dev-mtp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 6b7d1296e430..963449ec7de8 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -226,7 +226,7 @@ typedef struct {
     uint32_t assoc_desc;
     uint32_t seq_no; /*unused*/
     uint8_t length; /*part of filename field*/
-    uint16_t filename[0];
+    uint8_t filename[0]; /* UTF-16 encoded */
     char date_created[0]; /*unused*/
     char date_modified[0]; /*unused*/
     char keywords[0]; /*unused*/
@@ -1551,7 +1551,7 @@ static void usb_mtp_cancel_packet(USBDevice *dev, USBPacket *p)
     fprintf(stderr, "%s\n", __func__);
 }
 
-static char *utf16_to_str(uint8_t len, uint16_t *arr)
+static char *utf16_to_str(uint8_t len, uint8_t *str16)
 {
     wchar_t *wstr = g_new0(wchar_t, len + 1);
     int count, dlen;
@@ -1559,7 +1559,7 @@ static char *utf16_to_str(uint8_t len, uint16_t *arr)
 
     for (count = 0; count < len; count++) {
         /* FIXME: not working for surrogate pairs */
-        wstr[count] = (wchar_t)arr[count];
+        wstr[count] = lduw_le_p(str16 + (count * 2));
     }
     wstr[count] = 0;
 
-- 
2.18.1



  parent reply	other threads:[~2019-05-03  7:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03  6:59 [Qemu-devel] [PULL 0/7] Usb 20190503 v2 patches Gerd Hoffmann
2019-05-03  6:59 ` Gerd Hoffmann
2019-05-03  6:59 ` [Qemu-devel] [PULL 1/7] usb-mtp: fix string length for filename when writing metadata Gerd Hoffmann
2019-05-03  6:59   ` Gerd Hoffmann
2019-05-03  6:59 ` Gerd Hoffmann [this message]
2019-05-03  6:59   ` [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field Gerd Hoffmann
2019-05-03  6:59 ` [Qemu-devel] [PULL 3/7] usb-mtp: change default to success for usb_mtp_update_object Gerd Hoffmann
2019-05-03  6:59   ` Gerd Hoffmann
2019-05-03  6:59 ` [Qemu-devel] [PULL 4/7] usb/xhci: avoid trigger assertion if guest write wrong epid Gerd Hoffmann
2019-05-03  6:59   ` Gerd Hoffmann
2019-05-03  6:59 ` [Qemu-devel] [PULL 5/7] hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices in ohci_die() Gerd Hoffmann
2019-05-03  6:59   ` Gerd Hoffmann
2019-05-03  6:59 ` [Qemu-devel] [PULL 6/7] hw/usb/hcd-ohci: Move PCI-related code into a separate file Gerd Hoffmann
2019-05-03  6:59   ` Gerd Hoffmann
2019-05-03  6:59 ` [Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name Gerd Hoffmann
2019-05-03  6:59   ` Gerd Hoffmann
2021-01-18 11:31   ` Philippe Mathieu-Daudé
2021-01-18 11:35     ` Daniel P. Berrangé
2021-01-18 11:40       ` Philippe Mathieu-Daudé
2019-05-03 13:56 ` [Qemu-devel] [PULL 0/7] Usb 20190503 v2 patches Peter Maydell
2019-05-03 13:56   ` Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2019-05-02  7:35 [Qemu-devel] [PULL 0/7] Usb 20190502 patches Gerd Hoffmann
2019-05-02  7:35 ` [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field Gerd Hoffmann
2019-05-02  7:35   ` Gerd Hoffmann

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=20190503065954.17069-3-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).