From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mx.groups.io with SMTP id smtpd.web10.30627.1688384673049715765 for ; Mon, 03 Jul 2023 04:44:33 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@ventanamicro.com header.s=google header.b=eWygM6Yg; spf=pass (domain: ventanamicro.com, ip: 209.85.216.48, mailfrom: rsingh@ventanamicro.com) Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-262fa79e97fso2007050a91.2 for ; Mon, 03 Jul 2023 04:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688384672; x=1690976672; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4kBoUwRSayIkb4fgrlFTDCJukWcxb8m2Rgh0FYL+/+g=; b=eWygM6YgVy1MZb0K6sPkHj1YF8fhJsq8VhoZNJgG7WUQkXTKR869Sx+/+tsVReNMjF 9tbBdjAcJQXp9RV42cwT1Pjf7TtxOE+Mt3WlFChIlbombvYsbb9Mjd2EC90t9MpjtSbi n2xK/Fe1+4AnxcJkf2YhA/+VAVTknN2YVB5rAJ16JqMpvbnCY0kxp+wuRrY8E1/KhRGJ JJed+IrAvlxgh22Hi6fDJPkjy1ZsynObWGGUrspbBKdOSJHPiOKYIGp42AUmtko96HUw M/jkOlL3qlYm0YSkelnSwyf+vW/56ngz+DmInae33RAZ0BB+L0GuGtZ69oh1hfC+KxAr tpzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688384672; x=1690976672; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4kBoUwRSayIkb4fgrlFTDCJukWcxb8m2Rgh0FYL+/+g=; b=BRSJefDwh0i0z5axyU6qcC9WBzc5uzN5m+YB6g5YuGB7F2kiFTcXe3fbxhCN41lslU r79vkQlkgttsiPyDyzIH5f2iKpSp8jHAZGu4lZxm0SCbAxeb1o6PsoxNRExr6bcC4pcs GfwlE+KDdvHzdTqCN7HIHVcRoDC+4hhnwxV2uxjKGk2a1w7cTriVh3pQFv810mtF+Kbh VZrhWMrvdbxKQCojHZxJp1AWtrSS9qW2iJO/EHy8fl9zMEQnBS/Kcy2w7PvBGGzLyH1b V/qAcBNzd3fu47LucI+psJQBMsD+W90iwwedNzF5UHPozOEssKot0/mXtCakEbyKAtmn GTUQ== X-Gm-Message-State: ABy/qLalEbcAko+9fBkvhnI4T4lfeNsEALB1dmPCHZZhrz8BNLuhEW/Y 2ChJYdSniwedEsdfSpsHh3hpRnmOtok36u8HNmE= X-Google-Smtp-Source: APBJJlGOSWGwm8oWx6ZO7gvKG7iXuxqFH+Bsb3BBncpEpn71sUY/ktq72U09au4MK9Tr2Ce0dEgBjw== X-Received: by 2002:a17:90b:4d83:b0:259:24c4:4dd4 with SMTP id oj3-20020a17090b4d8300b0025924c44dd4mr8151531pjb.10.1688384672276; Mon, 03 Jul 2023 04:44:32 -0700 (PDT) Return-Path: Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1cbd:4608:e10e:762:23ef:5a24]) by smtp.gmail.com with ESMTPSA id gq7-20020a17090b104700b00263154aab24sm10411504pjb.57.2023.07.03.04.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 04:44:31 -0700 (PDT) From: Ranbir Singh To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Hao A Wu , Ray Ni Subject: [PATCH 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL Coverity issues Date: Mon, 3 Jul 2023 17:14:24 +0530 Message-Id: <20230703114424.227779-1-rsingh@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ranbir Singh The function UsbHcGetPciAddressForHostMem has ASSERT ((Block !=3D NULL)); and the UsbHcFreeMem has ASSERT (Block !=3D NULL); statement after for loop, but these are applicable only in DEBUG mode. In RELEASE mode, if for whatever reasons there is no match inside the for loop and the loop exits because of Block !=3D NULL; condition, then there is no "Block" NULL pointer check afterwards and the code proceeds to do dereferencing "Block" which will lead to CRASH. Hence, for safety add NULL pointer checks always. Cc: Hao A Wu Cc: Ray Ni REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4210 Signed-off-by: Ranbir Singh Signed-off-by: Ranbir Singh --- MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c b/MdeModulePkg/Bus/Pci= /EhciDxe/UsbHcMem.c index 0a3ceb9f711a..79575b6f6304 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c @@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem ( }=0D =0D ASSERT ((Block !=3D NULL));=0D +=0D + if (Block =3D=3D NULL) {=0D + return 0;=0D + }=0D +=0D //=0D // calculate the pci memory address for host memory address.=0D //=0D @@ -536,6 +541,10 @@ UsbHcFreeMem ( //=0D ASSERT (Block !=3D NULL);=0D =0D + if (Block =3D=3D NULL) {=0D + return;=0D + }=0D +=0D //=0D // Release the current memory block if it is empty and not the head=0D //=0D --=20 2.34.1