public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] NetworkPkg/IScsiDxe: Fix the index of array TargetUrlp[]
@ 2019-10-14  2:08 Zhang, Shenglei
  0 siblings, 0 replies; only message in thread
From: Zhang, Shenglei @ 2019-10-14  2:08 UTC (permalink / raw)
  To: devel; +Cc: Siyuan Fu, Jiaxin Wu

After the expression,
'CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);',
the '\0' should be set to TargetUrl[Field->Len] rather than
TargetUrl[Field->Len + 1].
Besides the boundary check should be more strict.
Field->Len should range from 0-254 rather than 0-255.

Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
 NetworkPkg/IScsiDxe/IScsiDhcp.c  | 7 ++++---
 NetworkPkg/IScsiDxe/IScsiDhcp6.c | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c b/NetworkPkg/IScsiDxe/IScsiDhcp.c
index d8c9fff6c65d..eac5b39991b7 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c
@@ -122,11 +122,12 @@ IScsiDhcpExtractRootPath (
   //
   if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) {
     ConfigNvData->DnsMode = TRUE;
-    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {
-      return EFI_INVALID_PARAMETER;
+    if (Field->Len >= sizeof (ConfigNvData->TargetUrl) {
+      Status = EFI_INVALID_PARAMETER;
+      goto ON_EXIT;
     }
     CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
-    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';
+    ConfigNvData->TargetUrl[Field->Len] = '\0';
   } else {
     ConfigNvData->DnsMode = FALSE;
     ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
index 86a872adeccc..be66e6684a0e 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
@@ -161,11 +161,12 @@ IScsiDhcp6ExtractRootPath (
   // Server name is expressed as domain name, just save it.
   //
   if (ConfigNvData->DnsMode) {
-    if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {
-      return EFI_INVALID_PARAMETER;
+    if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) {
+      Status = EFI_INVALID_PARAMETER;
+      goto ON_EXIT;
     }
     CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
-    ConfigNvData->TargetUrl[Field->Len + 1] = '\0';
+    ConfigNvData->TargetUrl[Field->Len] = '\0';
   } else {
     ZeroMem(&ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
     Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);
-- 
2.18.0.windows.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-10-14  2:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-14  2:08 [PATCH] NetworkPkg/IScsiDxe: Fix the index of array TargetUrlp[] Zhang, Shenglei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox