All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org, Benjamin David Lunt <benlunt@fysnet.net>,
	Thomas Huth <thuth@redhat.com>, Michael Tokarev <mjt@tls.msk.ru>
Subject: [Stable-7.2.10 49/54] hw/usb/bus.c: PCAP adding 0xA in Windows version
Date: Sun,  3 Mar 2024 10:39:28 +0300	[thread overview]
Message-ID: <20240303073934.1350568-2-mjt@tls.msk.ru> (raw)
In-Reply-To: <qemu-stable-7.2.10-20240303092734@cover.tls.msk.ru>

From: Benjamin David Lunt <benlunt@fysnet.net>

Since Windows text files use CRLFs for all \n, the Windows version of QEMU
inserts a CR in the PCAP stream when a LF is encountered when using USB PCAP
files. This is due to the fact that the PCAP file is opened as TEXT instead
of BINARY.

To show an example, when using a very common protocol to USB disks, the BBB
protocol uses a 10-byte command packet. For example, the READ_CAPACITY(10)
command will have a command block length of 10 (0xA). When this 10-byte
command (part of the 31-byte CBW) is placed into the PCAP file, the Windows
file manager inserts a 0xD before the 0xA, turning the 31-byte CBW into a
32-byte CBW.

Actual CBW:
  0040 55 53 42 43 01 00 00 00 08 00 00 00 80 00 0a 25 USBC...........%
  0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00       ...............

PCAP CBW
  0040 55 53 42 43 01 00 00 00 08 00 00 00 80 00 0d 0a USBC............
  0050 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 %..............

I believe simply opening the PCAP file as BINARY instead of TEXT will fix
this issue.

Resolves: https://bugs.launchpad.net/qemu/+bug/2054889
Signed-off-by: Benjamin David Lunt <benlunt@fysnet.net>
Message-ID: <000101da6823$ce1bbf80$6a533e80$@fysnet.net>
[thuth: Break long line to avoid checkpatch.pl error]
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 5e02a4fdebc442e34c5bb05e4540f85cc6e802f0)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 92d6ed5626..4d4c671913 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -273,13 +273,14 @@ static void usb_qdev_realize(DeviceState *qdev, Error **errp)
     }
 
     if (dev->pcap_filename) {
-        int fd = qemu_open_old(dev->pcap_filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
+        int fd = qemu_open_old(dev->pcap_filename,
+                               O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666);
         if (fd < 0) {
             error_setg(errp, "open %s failed", dev->pcap_filename);
             usb_qdev_unrealize(qdev);
             return;
         }
-        dev->pcap = fdopen(fd, "w");
+        dev->pcap = fdopen(fd, "wb");
         usb_pcap_init(dev->pcap);
     }
 }
-- 
2.39.2



  parent reply	other threads:[~2024-03-03  7:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03  7:39 [Stable-7.2.10 v3 00/54] Patch Round-up for stable 7.2.10, freeze on 2024-03-02 (frozen) Michael Tokarev
2024-03-03  7:39 ` [Stable-7.2.10 48/54] gitlab: force allow use of pip in Cirrus jobs Michael Tokarev
2024-03-03  7:39 ` Michael Tokarev [this message]
2024-03-03  7:39 ` [Stable-7.2.10 50/54] tests/unit/test-util-sockets: Remove temporary file after test Michael Tokarev
2024-03-03  7:39 ` [Stable-7.2.10 51/54] test-vmstate: fix bad GTree usage, use-after-free Michael Tokarev
2024-03-03  7:39 ` [Stable-7.2.10 52/54] tests/qtest/display-vga-test: Add proper checks if a device is available Michael Tokarev
2024-03-03  7:39 ` [Stable-7.2.10 53/54] tests/unit/test-blockjob: Disable complete_in_standby test Michael Tokarev
2024-03-03  7:39 ` [Stable-7.2.10 54/54] target/i386: the sgx_epc_get_section stub is reachable Michael Tokarev

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=20240303073934.1350568-2-mjt@tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=benlunt@fysnet.net \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=thuth@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.