From patchwork Tue Apr 2 06:46:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 161613 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1392222jan; Tue, 2 Apr 2019 00:05:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/3oD9kkv53A7+i2l2U5dZiIfR5yN5tlK/k3fh015q/4uw3/E2zikmOOdOV0hi5/2uUwWz X-Received: by 2002:a0d:d810:: with SMTP id a16mr22506412ywe.195.1554188738691; Tue, 02 Apr 2019 00:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554188738; cv=none; d=google.com; s=arc-20160816; b=xrrMcWQBLp9iRGy0uc3+tWabIMuI+sXzdCFLHMhsQU/T/Uyr8dPPjVjm4RTxyCiau6 1w4MEZ20oss1Fu93OJcsFLtrR5rSyYVLDuL6CkN8gTNZ0bdw807Hm33umZ020eTYvi2L kR7KBfKmSPlu0ZMncilVvZS6a8hRsgj6LuBlf67T5JYKJe7TtGFjKOLtHJM1zDO1lJ24 FCYVfTaCx0Ar3C35hq9ZTZXoRYbakoho4TUWAabsRYAWEmYzuhgvpUEYJlSQ3dvrxBlJ A/FH1jPABmO+/vIcnHvTVPiGIFi5uvd35ZsXdeEsOr6cZp8yp7vSp8dp0++CQBqftpcr skSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=0e74h5BbvhQKcFmSKHnMrpFeCPrUwPeZwiYhxPaADHM=; b=vsAasw4q5KdMCCZ4SNRHDTMh9qr4COY3QXEmja7w2olO2nYSEhtGmn3M+vlhkHNw8H 3ePtr8+pPZGdrdqgKtWIDR3ZOn7i1LMsCty8bk1jLRyrSuVbG8aSv1CFcs86i62cwvUP NpDmO3nEVztMSMqKeUMGdlbNU+V/xVqos+FegQVm12fwdnye4gegUKXV2Q+z2Yd+DADm ceKO5hPHk3yCirgjQ7E0cak/ICMUXWcoIENhhBB2dVaUpRe2vwTrBLsAuQpWQjFtQ2JS UTkS68Jx/TBKlHZoVOxae+C6T/ttjgErqyhbO3n5jUYs0gY+jxPm+EkSjm1b37hQ7Kab IVBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o2si7030634ybp.49.2019.04.02.00.05.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 02 Apr 2019 00:05:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([127.0.0.1]:40305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBDUI-0003XQ-4x for patch@linaro.org; Tue, 02 Apr 2019 03:05:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBDQp-0000rc-0o for qemu-devel@nongnu.org; Tue, 02 Apr 2019 03:02:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBDQn-0005bJ-1Y for qemu-devel@nongnu.org; Tue, 02 Apr 2019 03:02:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hBDC0-0005Qi-L3 for qemu-devel@nongnu.org; Tue, 02 Apr 2019 02:46:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C79B30820EA; Tue, 2 Apr 2019 06:46:43 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3BB65C290; Tue, 2 Apr 2019 06:46:40 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EE0CBA1E3; Tue, 2 Apr 2019 08:46:39 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 2 Apr 2019 08:46:36 +0200 Message-Id: <20190402064639.27108-3-kraxel@redhat.com> In-Reply-To: <20190402064639.27108-1-kraxel@redhat.com> References: <20190402064639.27108-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 02 Apr 2019 06:46:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/5] hw/usb/bus.c: Handle "no speed matched" case in usb_mask_to_str() 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 , Gerd Hoffmann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell In usb_mask_to_str() we convert a mask of USB speeds into a human-readable string (like "full+high") for use in tracing and error messages. However the conversion code doesn't do anything to the string buffer if the passed in speedmask doesn't match any of the recognized speeds, which means that the tracing and error messages will end up with random garbage in them. This can happen if we're doing USB device passthrough. Handle the "unrecognized speed" case by using the string "unknown". Fixes: https://bugs.launchpad.net/qemu/+bug/1603785 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 20190328133503.6490-1-peter.maydell@linaro.org Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.18.1 diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 6fffab7bfa44..9a74dc956010 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -500,6 +500,10 @@ static void usb_mask_to_str(char *dest, size_t size, speeds[i].name); } } + + if (pos == 0) { + snprintf(dest, size, "unknown"); + } } void usb_check_attach(USBDevice *dev, Error **errp)