From patchwork Thu Feb 28 17:57:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 1049654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449KzP6w06z9s4V for ; Fri, 1 Mar 2019 04:58:25 +1100 (AEDT) Received: from localhost ([127.0.0.1]:44201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPwu-0000zw-1W for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 12:58:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPwF-0000tw-Qr for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:57:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzPwE-0000bp-E8 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:57:43 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34322) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzPwD-0000ZM-To for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:57:42 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1SHtkmH011343 for ; Thu, 28 Feb 2019 12:57:40 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2qxhwb8vpb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Feb 2019 12:57:39 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Feb 2019 17:57:37 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 28 Feb 2019 17:57:34 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1SHvXw332178278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 28 Feb 2019 17:57:33 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D6B1A404D; Thu, 28 Feb 2019 17:57:33 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 595BEA4053; Thu, 28 Feb 2019 17:57:33 +0000 (GMT) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 28 Feb 2019 17:57:33 +0000 (GMT) Received: from bahia.lan (sig-9-145-41-217.uk.ibm.com [9.145.41.217]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id D935F220158; Thu, 28 Feb 2019 18:57:32 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2019 18:57:32 +0100 User-Agent: StGit/unknown-version MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19022817-4275-0000-0000-0000031535A6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19022817-4276-0000-0000-000038237D73 Message-Id: <155137665241.44413.528147250140332507.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-28_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=13 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=904 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902280122 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id x1SHtkmH011343 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH] usb-mtp: Fix build with gcc 9 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Build fails with gcc 9: CC hw/usb/dev-mtp.o hw/usb/dev-mtp.c: In function ‘usb_mtp_write_metadata’: hw/usb/dev-mtp.c:1754:36: error: taking address of packed member of ‘struct ’ may result in an unaligned pointer value [-Werror=address-of-packed-member] 1754 | dataset->filename); | ~~~~~~~^~~~~~~~~~ cc1: all warnings being treated as errors The way the MTP protocol encodes strings with a leading 8-bit unsigned integer containing the string length causes the @filename field of the packed ObjectInfo structure to be unaligned. Use a temporary buffer for the utf16 filename instead of passing the dataset->filename pointer around. Signed-off-by: Greg Kurz --- hw/usb/dev-mtp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 4ee4fc5a893a..8a0ef7f9f4a8 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -1692,13 +1692,25 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen) MTPObject *o; MTPObject *p = usb_mtp_object_lookup(s, s->dataset.parent_handle); uint32_t next_handle = s->next_handle; + uint16_t *utf16_filename; + uint8_t filename_len; assert(!s->write_pending); assert(p != NULL); - filename = utf16_to_str(MIN(dataset->length, - dlen - offsetof(ObjectInfo, filename)), - dataset->filename); + /* + * MTP Specification 3.2.3 Strings + * Strings in PTP (and thus MTP) consist of standard 2-byte Unicode + * characters as defined by ISO 10646. Strings begin with a single, 8-bit + * unsigned integer that identifies the number of characters to follow (not + * bytes). + * + * This causes dataset->filename to be unaligned. + */ + filename_len = MIN(dataset->length, dlen - offsetof(ObjectInfo, filename)); + utf16_filename = g_memdup(dataset->filename, filename_len * 2); + filename = utf16_to_str(filename_len, utf16_filename); + g_free(utf16_filename); if (strchr(filename, '/')) { usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,