[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 4/9] ccid-card-passthru: Let the chardev::rea
From: |
Marc-André Lureau |
Subject: |
Re: [Qemu-devel] [PATCH v2 4/9] ccid-card-passthru: Let the chardev::read() be more generic |
Date: |
Fri, 15 Feb 2019 12:43:12 +0100 |
Hi
On Thu, Feb 14, 2019 at 9:20 PM Philippe Mathieu-Daudé
<address@hidden> wrote:
>
> Suggested-by: Paolo Bonzini <address@hidden>
> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
> hw/usb/ccid-card-passthru.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
> index 0c44b38fc2..ba7c285ded 100644
> --- a/hw/usb/ccid-card-passthru.c
> +++ b/hw/usb/ccid-card-passthru.c
> @@ -285,8 +285,14 @@ static void ccid_card_vscard_read(void *opaque, const
> uint8_t *buf, int size)
> card->vscard_in_hdr += hdr->length + sizeof(VSCMsgHeader);
> hdr = (VSCMsgHeader *)(card->vscard_in_data + card->vscard_in_hdr);
> }
> - if (card->vscard_in_hdr == card->vscard_in_pos) {
> - card->vscard_in_pos = card->vscard_in_hdr = 0;
Interesting, it looks like we could end in a blocking condition today.
card->vscard_in_pos - card->vscard_in_hdr could not have enough room
to process an incoming message. After filling the buffer, it would
stop reading.
> +
> + /* Drop any messages that were fully processed. */
> + if (card->vscard_in_hdr > 0) {
> + memmove(card->vscard_in_data,
> + card->vscard_in_data + card->vscard_in_hdr,
> + card->vscard_in_pos - card->vscard_in_hdr);
> + card->vscard_in_pos -= card->vscard_in_hdr;
> + card->vscard_in_hdr = 0;
> }
> }
At least, by moving data around, this would leave always enough space
for the header to be fully read.
But I think we should add a condition like
card->vscard_in_hdr + hdr->length + sizeof(VSCMsgHeader) <=
VSCARD_IN_SIZE, to make sure the incoming message fits in the
vscard_in_data buffer, else disconnect?
>
> --
> 2.20.1
>
- [Qemu-devel] [PATCH v2 1/9] ccid-card-passthru: Move assertion in read() to can_read(), (continued)
- [Qemu-devel] [PATCH v2 1/9] ccid-card-passthru: Move assertion in read() to can_read(), Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 2/9] ccid-card-passthru: Replace never trigger if statement by an assertion, Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 3/9] ccid-card-passthru: Assert on a stricter expression, Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 4/9] ccid-card-passthru: Let the chardev::read() be more generic, Philippe Mathieu-Daudé, 2019/02/14
- Re: [Qemu-devel] [PATCH v2 4/9] ccid-card-passthru: Let the chardev::read() be more generic,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v2 5/9] ccid-card-passthru: Replace assert() by QEMU_BUILD_BUG_ON(), Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 7/9] ccid-card-passthru: Use QERR_MISSING_PARAMETER, Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 6/9] ccid-card-passthru: Simplify the if() condition, Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 9/9] ccid-card-passthru: Use size_t for index, Philippe Mathieu-Daudé, 2019/02/14
- [Qemu-devel] [PATCH v2 8/9] ccid-card-passthru: Use size_t to hold size argument, Philippe Mathieu-Daudé, 2019/02/14