]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix the issue that null pointer may be dereferenced at SourceLevelDebugPkg
authorerictian <erictian@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Sep 2011 08:07:54 +0000 (08:07 +0000)
committererictian <erictian@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Sep 2011 08:07:54 +0000 (08:07 +0000)
Signed-off-by: erictian
Reviewed-by: ydong10
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12389 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c

index 588e45853d49b437bdaca09b78dce0631915612c..59189db0dc4e865073419426f2c1b9108a48eb3f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Port Library implementation based on usb debug port.\r
 \r
 /** @file\r
   Debug Port Library implementation based on usb debug port.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -285,6 +285,7 @@ UsbDebugPortIn (
   }\r
 \r
   *Length = (UINT8)(MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & 0xF);\r
   }\r
 \r
   *Length = (UINT8)(MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & 0xF);\r
+  ASSERT (*Length <= 8);\r
   for (Index = 0; Index < *Length; Index++) {\r
     Buffer[Index] = DebugPortRegister->DataBuffer[Index];\r
   }\r
   for (Index = 0; Index < *Length; Index++) {\r
     Buffer[Index] = DebugPortRegister->DataBuffer[Index];\r
   }\r
@@ -402,6 +403,7 @@ UsbDebugPortControlTransfer (
 {\r
   RETURN_STATUS          Status;\r
   UINT8                  Temp;\r
 {\r
   RETURN_STATUS          Status;\r
   UINT8                  Temp;\r
+  UINT8                  ReturnStatus[8];\r
 \r
   //\r
   // Setup Phase\r
 \r
   //\r
   // Setup Phase\r
@@ -414,7 +416,7 @@ UsbDebugPortControlTransfer (
   //\r
   // Data Phase\r
   //\r
   //\r
   // Data Phase\r
   //\r
-  if (SetupPacket->Length != 0) {\r
+  if (DataLength != 0) {\r
     if ((SetupPacket->RequestType & BIT7) != 0) {\r
       //\r
       // Get Data From Device\r
     if ((SetupPacket->RequestType & BIT7) != 0) {\r
       //\r
       // Get Data From Device\r
@@ -446,7 +448,7 @@ UsbDebugPortControlTransfer (
     //\r
     // For WRITE operation, Data Toggle in Status Phase Should be 1.\r
     //\r
     //\r
     // For WRITE operation, Data Toggle in Status Phase Should be 1.\r
     //\r
-    Status = UsbDebugPortIn(DebugPortRegister, NULL, &Temp, INPUT_PID, Addr, Ep, 1);\r
+    Status = UsbDebugPortIn(DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);\r
   }\r
 \r
   return Status;\r
   }\r
 \r
   return Status;\r
@@ -641,11 +643,11 @@ InitializeUsbDebugHardware (
     //\r
     return Status;\r
   }\r
     //\r
     return Status;\r
   }\r
-\r
+  ASSERT (Length == sizeof(USB_DEBUG_PORT_DESCRIPTOR));\r
   //\r
   // set usb debug device address as 0x7F.\r
   //\r
   //\r
   // set usb debug device address as 0x7F.\r
   //\r
-  Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mSetDebugAddress, 0x0, 0x0, (UINT8*)&UsbDebugPortDescriptor, &Length);\r
+  Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mSetDebugAddress, 0x0, 0x0, NULL, NULL);\r
   if (RETURN_ERROR(Status)) {\r
     //\r
     // The device can not work well.\r
   if (RETURN_ERROR(Status)) {\r
     //\r
     // The device can not work well.\r