From: "Tommaso Califano" <tcalifano@redhat.com>
To: <marcandre.lureau@redhat.com>, "Tommaso Califano" <tcalifano@redhat.com>
Cc: <qemu-devel@nongnu.org>, "Markus Armbruster" <armbru@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Junjie Cao" <junjie.cao@linux.dev>, <qemu-stable@nongnu.org>
Subject: Re: [PATCH 4/9] hw/usb/dev-mtp: Handle invalid characters in utf16_to_str()
Date: Fri, 13 Nov 2026 14:16:14 +0100 [thread overview]
Message-ID: <DMU40PL5P526.2IC1F99D8AW9@redhat.com> (raw)
In-Reply-To: <179455878072.754321.10848127829960266585.b4-review@b4>
On Fri Nov 13, 2026 at 9:33 AM CET, marcandre.lureau wrote:
>> wcstombs(NULL, wstr, 0) returns (size_t)-1 when the string contains a
>> character that cannot be converted. The return value was not checked, so
>> dlen + 1 wrapped to 0, g_malloc(0) returned NULL, and
>> usb_mtp_write_metadata() dereferenced it in strchr().
>>
>> Use size_t, return NULL on conversion failure, and reject the
>> filename in usb_mtp_write_metadata() when that happens.
>>
>> Cc: qemu-stable@nongnu.org
>> Fixes: 6de02a13232a ("usb-mtp: fix utf16_to_str")
>> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4529
>> Suggested-by: Hui Peng <https://gitlab.com/benquike>
>> Signed-off-by: Tommaso Califano <tcalifano@redhat.com>
>> Message-ID: <20261112174907.158825-5-tcalifano@redhat.com>
>> ---
>> hw/usb/dev-mtp.c | 15 ++++++++++-----
>> 1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
>> index 1a26f681ce5f..7233470558db 100644
>> --- a/hw/usb/dev-mtp.c
>> +++ b/hw/usb/dev-mtp.c
>> @@ -1563,7 +1563,8 @@ static void usb_mtp_cancel_packet(USBDevice *dev, USBPacket *p)
>> static char *utf16_to_str(uint8_t len, uint8_t *str16)
>> {
>> wchar_t *wstr = g_new0(wchar_t, len + 1);
>> - int count, dlen;
>> + int count;
>> + size_t dlen;
>> char *dest;
>>
>> for (count = 0; count < len; count++) {
>> @@ -1572,9 +1573,13 @@ static char *utf16_to_str(uint8_t len, uint8_t *str16)
>> }
>> wstr[count] = 0;
>>
>> - dlen = wcstombs(NULL, wstr, 0) + 1;
>> - dest = g_malloc(dlen);
>> - wcstombs(dest, wstr, dlen);
>> + dlen = wcstombs(NULL, wstr, 0);
>
> Can we replace this function with g_utf16_to_utf8() which is not
> sensible to locale. If not, a comment could be useful.
Sure. I wasn’t aware of that function, but it does seem like a perfect
fit. Thanks!
Thanks,
Tommaso
next prev parent reply other threads:[~2026-11-13 13:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 17:48 [PATCH 0/9] hw/usb/dev-mtp: Collection of bug fixes Tommaso Califano
2026-11-12 17:48 ` [PATCH 1/9] hw/usb/dev-mtp: Fix recursive delete of directories Tommaso Califano
2026-11-12 17:48 ` [PATCH 2/9] hw/usb/dev-mtp: Reset pending write state on cancel, reset and error Tommaso Califano
2026-11-13 8:33 ` marcandre.lureau
2026-11-13 11:46 ` Tommaso Califano
2026-11-12 17:49 ` [PATCH 3/9] hw/usb/dev-mtp: Check length of class control request Tommaso Califano
2026-11-13 8:33 ` marcandre.lureau
2026-11-12 17:49 ` [PATCH 4/9] hw/usb/dev-mtp: Handle invalid characters in utf16_to_str() Tommaso Califano
2026-11-13 8:33 ` marcandre.lureau
2026-11-13 13:16 ` Tommaso Califano [this message]
2026-11-12 17:49 ` [PATCH 5/9] hw/usb/dev-mtp: Validate container length on first data packet Tommaso Califano
2026-11-13 8:33 ` marcandre.lureau
2026-11-13 13:18 ` Tommaso Califano
2026-11-12 17:49 ` [PATCH 6/9] hw/usb/dev-mtp: Detect end of SendObject data correctly Tommaso Califano
2026-11-12 17:49 ` [PATCH 7/9] hw/usb/dev-mtp: Zero-initialize command and params in handle_data Tommaso Califano
2026-11-12 17:49 ` [PATCH 8/9] hw/usb/dev-mtp: Fix assert failures in usb_mtp_write_metadata() Tommaso Califano
2026-11-12 17:49 ` [PATCH 9/9] hw/usb/dev-mtp: Stop processing SendObjectInfo after an error Tommaso Califano
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=DMU40PL5P526.2IC1F99D8AW9@redhat.com \
--to=tcalifano@redhat.com \
--cc=armbru@redhat.com \
--cc=junjie.cao@linux.dev \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=richard.henderson@linaro.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 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.