From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.7998.1687429330466021650 for ; Thu, 22 Jun 2023 03:22:10 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Opfq5sLI; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687429329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i4Cdwt34BJIzjOoszRGiWHxs/DupagKaqOxPzhhDJ4U=; b=Opfq5sLImXjbLNZz1pqA/24yBmbYAbURiyezAFzFCZloZ7NNB43g9B/HqSdDph3vF0YAtS 1wxOXDN0wZuFE5qdz3SV/tkNjFP3X2wue1GmsbdZ0q6fSTx0qhj3x+5u0z9chH8GYxWqtA Q0VX2g8FZjIm8Kd2Mza3SzrpTCr8DNs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-B9XSK4o3N4G2F1kNMOCbYg-1; Thu, 22 Jun 2023 06:22:06 -0400 X-MC-Unique: B9XSK4o3N4G2F1kNMOCbYg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE92E185A792; Thu, 22 Jun 2023 10:22:05 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9749D112132C; Thu, 22 Jun 2023 10:22:05 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2EAF91800639; Thu, 22 Jun 2023 12:22:04 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Maciej Rabeda , Siyuan Fu , Oliver Steffen , Gerd Hoffmann , Jeremy Boone Subject: [PATCH 1/1] NetworkPkg/IScsiDxe: add checks to IScsiBuildKeyValueList Date: Thu, 22 Jun 2023 12:22:04 +0200 Message-ID: <20230622102204.331528-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Check we have any data left (Len > 0) before advancing the Data pointer and reducing Len. Avoids wrapping Len. Also replace the AsciiStrLen() call with an open-coded loop which likewise checks Len to make sure we don't overrun the buffer. Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4207 Reported-by: Jeremy Boone Signed-off-by: Gerd Hoffmann --- NetworkPkg/IScsiDxe/IScsiProto.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/NetworkPkg/IScsiDxe/IScsiProto.c b/NetworkPkg/IScsiDxe/IScsiProto.c index ef587649a05e..88e7946d3f78 100644 --- a/NetworkPkg/IScsiDxe/IScsiProto.c +++ b/NetworkPkg/IScsiDxe/IScsiProto.c @@ -1903,9 +1903,8 @@ IScsiBuildKeyValueList ( Data++; } - if (*Data == '=') { + if ((Len > 0) && (*Data == '=')) { *Data = '\0'; - Data++; Len--; } else { @@ -1917,8 +1916,17 @@ IScsiBuildKeyValueList ( InsertTailList (ListHead, &KeyValuePair->List); - Data += AsciiStrLen (KeyValuePair->Value) + 1; - Len -= (UINT32)AsciiStrLen (KeyValuePair->Value) + 1; + while ((Len > 0) && (*Data != '\0')) { + Len--; + Data++; + } + + if ((Len > 0) && (*Data == '\0')) { + Data++; + Len--; + } else { + goto ON_ERROR; + } } return ListHead; -- 2.41.0