From nobody Fri Nov 7 19:47:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548859235209625.3865578870268; Wed, 30 Jan 2019 06:40:35 -0800 (PST) Received: from localhost ([127.0.0.1]:39210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gor2W-0007pP-GQ for importer@patchew.org; Wed, 30 Jan 2019 09:40:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gor0w-0006sN-UN for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gor0w-0001Je-5z for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:54 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:45582) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gor0v-0001J2-Tw for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:54 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0UETU2G036052; Wed, 30 Jan 2019 14:38:52 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2q8d2eb4km-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 14:38:52 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0UEco05025320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 14:38:51 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0UEcowa021772; Wed, 30 Jan 2019 14:38:50 GMT Received: from ol7.nl.oracle.com (/10.175.63.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 Jan 2019 06:38:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=5U/VMXy7hiNMt0QnqXzwUgw9ySoY7uF5DnqOMSQG4cY=; b=3IwVjd9F+ID3Qw7l6+tcfhR1XzbatllwcScxyJDGraA9iZa83UrNS4TEQWauG/jg2ey2 9vEqK/v19Yw6qzoJ/mx3mmNLpHXEt+HFYpFpzyhqXcahQQjCpOGrALGScn5UM513a/DB ci4WcAiT9dj9+P+fQKp3GFXsppwduFRWRbYRt/l9hQ+b7c54xpE3WjX+Tgx+g2ra6J+j RqKKVtTfHLMwA6YFvs0jwbD7C/lBwkQxeKBFqDWAnR0tovI4LONqrju/+62EfRsMXTZt U6lzDsZtmlxN1p1QR3+kquxsqLsyPiu+ZyaYSvf7vzLsqcwr0pNsO7Xk3jTp4mmCpGPR zQ== From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 14:37:01 +0000 Message-Id: <1548859022-3969-2-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> References: <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9151 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=921 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901300115 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH 1/2] usb: rearrange usb_ep_get() 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: ameya.more@oracle.com, Darren.Kenny@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is no need to calculate the 'eps' variable in usb_ep_get() if 'ep' is the control endpoint. Instead the calculation should be done after validating the input and the resulting pointer also validated before returning an entry indexed on the endpoint 'ep'. Signed-off-by: Liam Merwick Reviewed-by: Darren Kenny Reviewed-by: Mark Kanda Reviewed-by: Ameya More --- hw/usb/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/core.c b/hw/usb/core.c index 241ae66b1505..1aa0051b2b2d 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -720,12 +720,13 @@ struct USBEndpoint *usb_ep_get(USBDevice *dev, int pi= d, int ep) if (dev =3D=3D NULL) { return NULL; } - eps =3D (pid =3D=3D USB_TOKEN_IN) ? dev->ep_in : dev->ep_out; if (ep =3D=3D 0) { return &dev->ep_ctl; } assert(pid =3D=3D USB_TOKEN_IN || pid =3D=3D USB_TOKEN_OUT); assert(ep > 0 && ep <=3D USB_MAX_ENDPOINTS); + eps =3D (pid =3D=3D USB_TOKEN_IN) ? dev->ep_in : dev->ep_out; + assert(eps !=3D NULL); return eps + ep - 1; } =20 --=20 1.8.3.1 From nobody Fri Nov 7 19:47:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548859233817226.9646072224525; Wed, 30 Jan 2019 06:40:33 -0800 (PST) Received: from localhost ([127.0.0.1]:39202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gor2V-0007oO-FU for importer@patchew.org; Wed, 30 Jan 2019 09:40:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gor0x-0006sT-6m for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gor0w-0001Jl-Ab for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:55 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:49876) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gor0w-0001JB-2M for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:54 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0UETWsk052028; Wed, 30 Jan 2019 14:38:53 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2q8g6ratj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 14:38:53 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0UEcqqV026954 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 14:38:52 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0UEcqjF021777; Wed, 30 Jan 2019 14:38:52 GMT Received: from ol7.nl.oracle.com (/10.175.63.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 Jan 2019 06:38:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=priW+8Xo0HHM0dxvdwNedSrrcFYg1J9OpTqcJhmJrAQ=; b=xsGF4/0ryraArt/VpePczAwxHL5BjajfW5V1QbdWxu6Yfq0nDsoRXSRXtJ0vg0aTJ+my l0riyha8396peggKLl3kRBqPZ+ReDSGuiUfZ5rsRhX6Cr4xsBi2yp3G37gUDoguKdRT5 QICEWiTNoPgK1a/Zbp9HzTaz7lweav8ZboMG+LHuYCGeZhq4Z/+Af/WnT9go8D2OqIHN fEilG7VA3dVLz6MRRf3bUasgEFJjMWYKZE4P9zqLcgUI7wwnnte8pOTmlQaBg0YCjDU+ MN+NloiPb5HGjs25VYporM7tGF4XXxAPD99F8sNl0ye7WSf87Aw3oZWwwxo88lTWKbVj UQ== From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 14:37:02 +0000 Message-Id: <1548859022-3969-3-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> References: <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9151 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901300115 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH 2/2] usb: deal with potential Null pointer returned by usb_ep_get() 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: ameya.more@oracle.com, Darren.Kenny@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Liam Merwick usb_ep_get() can return a Null pointer in the (albeit unlikely) case that a NULL USBDevice is passed in via the 'dev' parameter. Before dereferencing the return value from usb_ep_get(), check its validity and use a default (invalid) value where needed. Reported by the Parfait static code analysis tool Signed-off-by: Liam Merwick Reviewed-by: Darren Kenny Reviewed-by: Mark Kanda Reviewed-by: Ameya More --- hw/usb/core.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/hw/usb/core.c b/hw/usb/core.c index 1aa0051b2b2d..9d46a4b41e99 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -733,19 +733,23 @@ struct USBEndpoint *usb_ep_get(USBDevice *dev, int pi= d, int ep) uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep) { struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); - return uep->type; + return uep ? uep->type : USB_ENDPOINT_XFER_INVALID; } =20 void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type) { struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); - uep->type =3D type; + if (uep) { + uep->type =3D type; + } } =20 void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum) { struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); - uep->ifnum =3D ifnum; + if (uep) { + uep->ifnum =3D ifnum; + } } =20 void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, @@ -754,6 +758,10 @@ void usb_ep_set_max_packet_size(USBDevice *dev, int pi= d, int ep, struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); int size, microframes; =20 + if (!uep) { + return; + } + size =3D raw & 0x7ff; switch ((raw >> 11) & 3) { case 1: @@ -774,6 +782,10 @@ void usb_ep_set_max_streams(USBDevice *dev, int pid, i= nt ep, uint8_t raw) struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); int MaxStreams; =20 + if (!uep) { + return; + } + MaxStreams =3D raw & 0x1f; if (MaxStreams) { uep->max_streams =3D 1 << MaxStreams; @@ -785,7 +797,9 @@ void usb_ep_set_max_streams(USBDevice *dev, int pid, in= t ep, uint8_t raw) void usb_ep_set_halted(USBDevice *dev, int pid, int ep, bool halted) { struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); - uep->halted =3D halted; + if (uep) { + uep->halted =3D halted; + } } =20 USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep, @@ -794,6 +808,10 @@ USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, in= t pid, int ep, struct USBEndpoint *uep =3D usb_ep_get(dev, pid, ep); USBPacket *p; =20 + if (!uep) { + return NULL; + } + QTAILQ_FOREACH(p, &uep->queue, queue) { if (p->id =3D=3D id) { return p; --=20 1.8.3.1