]> git.proxmox.com Git - mirror_edk2.git/commitdiff
fixes for NULL verification.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 6 Dec 2010 18:10:34 +0000 (18:10 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 6 Dec 2010 18:10:34 +0000 (18:10 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11125 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/ShellEnvVar.c
ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c

index f22fb705ddec82330397f8d1fa9ce07b8d6fdcb9..519181b56ddbb4e5cb998d4e4b65b40891df8554 100644 (file)
@@ -183,7 +183,7 @@ GetEnvironmentVariableList(
             Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);\r
           }\r
         }\r
             Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);\r
           }\r
         }\r
-        if (!EFI_ERROR(Status)) {\r
+        if (!EFI_ERROR(Status) && VarList != NULL) {\r
           VarList->Key = AllocatePool(StrSize(VariableName));\r
           if (VarList->Key == NULL) {\r
             SHELL_FREE_NON_NULL(VarList->Val);\r
           VarList->Key = AllocatePool(StrSize(VariableName));\r
           if (VarList->Key == NULL) {\r
             SHELL_FREE_NON_NULL(VarList->Val);\r
index 0f799786ee3fb28aa571a8d1a564d8c0b9154de7..19759cbb2bbbf5194a887f782b759818d9d7768d 100644 (file)
@@ -907,75 +907,46 @@ InternalOpenFileDevicePath(
 \r
   if (!EFI_ERROR(Status)) {\r
     Handle1 = ConvertShellHandleToEfiFileProtocol(ShellHandle);\r
 \r
   if (!EFI_ERROR(Status)) {\r
     Handle1 = ConvertShellHandleToEfiFileProtocol(ShellHandle);\r
-    //\r
-    // chop off the begining part before the file system part...\r
-    //\r
-    ///@todo BlockIo?\r
-    Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid,\r
-                                   &DevicePath,\r
-                                   &Handle);\r
-      if (!EFI_ERROR(Status)) {\r
+    if (Handle1 != NULL) {\r
       //\r
       //\r
-      // To access as a file system, the file path should only\r
-      // contain file path components.  Follow the file path nodes\r
-      // and find the target file\r
+      // chop off the begining part before the file system part...\r
       //\r
       //\r
-      for ( FilePathNode = (FILEPATH_DEVICE_PATH *)DevicePath\r
-          ; !IsDevicePathEnd (&FilePathNode->Header)\r
-          ; FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header)\r
-         ){\r
-        SHELL_FREE_NON_NULL(AlignedNode);\r
-        AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePathNode), FilePathNode);\r
-        //\r
-        // For file system access each node should be a file path component\r
-        //\r
-        if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||\r
-            DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP\r
-           ) {\r
-          Status = EFI_UNSUPPORTED;\r
-          break;\r
-        }\r
-\r
-        //\r
-        // Open this file path node\r
-        //\r
-        Handle2 = Handle1;\r
-        Handle1 = NULL;\r
-\r
+      ///@todo BlockIo?\r
+      Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid,\r
+                                     &DevicePath,\r
+                                     &Handle);\r
+        if (!EFI_ERROR(Status)) {\r
         //\r
         //\r
-        // if this is the last node in the DevicePath always create (if that was requested).\r
+        // To access as a file system, the file path should only\r
+        // contain file path components.  Follow the file path nodes\r
+        // and find the target file\r
         //\r
         //\r
-        if (IsDevicePathEnd ((NextDevicePathNode (&FilePathNode->Header)))) {\r
-          Status = Handle2->Open (\r
-                                Handle2,\r
-                                &Handle1,\r
-                                AlignedNode->PathName,\r
-                                OpenMode,\r
-                                Attributes\r
-                               );\r
-        } else {\r
-\r
+        for ( FilePathNode = (FILEPATH_DEVICE_PATH *)DevicePath\r
+            ; !IsDevicePathEnd (&FilePathNode->Header)\r
+            ; FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header)\r
+           ){\r
+          SHELL_FREE_NON_NULL(AlignedNode);\r
+          AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePathNode), FilePathNode);\r
           //\r
           //\r
-          //  This is not the last node and we dont want to 'create' existing\r
-          //  directory entries...\r
+          // For file system access each node should be a file path component\r
           //\r
           //\r
+          if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||\r
+              DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP\r
+             ) {\r
+            Status = EFI_UNSUPPORTED;\r
+            break;\r
+          }\r
 \r
           //\r
 \r
           //\r
-          // open without letting it create\r
-          // prevents error on existing files/directories\r
+          // Open this file path node\r
           //\r
           //\r
-          Status = Handle2->Open (\r
-                                Handle2,\r
-                                &Handle1,\r
-                                AlignedNode->PathName,\r
-                                OpenMode &~EFI_FILE_MODE_CREATE,\r
-                                Attributes\r
-                               );\r
+          Handle2 = Handle1;\r
+          Handle1 = NULL;\r
+\r
           //\r
           //\r
-          // if above failed now open and create the 'item'\r
-          // if OpenMode EFI_FILE_MODE_CREATE bit was on (but disabled above)\r
+          // if this is the last node in the DevicePath always create (if that was requested).\r
           //\r
           //\r
-          if ((EFI_ERROR (Status)) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)) {\r
+          if (IsDevicePathEnd ((NextDevicePathNode (&FilePathNode->Header)))) {\r
             Status = Handle2->Open (\r
                                   Handle2,\r
                                   &Handle1,\r
             Status = Handle2->Open (\r
                                   Handle2,\r
                                   &Handle1,\r
@@ -983,20 +954,51 @@ InternalOpenFileDevicePath(
                                   OpenMode,\r
                                   Attributes\r
                                  );\r
                                   OpenMode,\r
                                   Attributes\r
                                  );\r
+          } else {\r
+\r
+            //\r
+            //  This is not the last node and we dont want to 'create' existing\r
+            //  directory entries...\r
+            //\r
+\r
+            //\r
+            // open without letting it create\r
+            // prevents error on existing files/directories\r
+            //\r
+            Status = Handle2->Open (\r
+                                  Handle2,\r
+                                  &Handle1,\r
+                                  AlignedNode->PathName,\r
+                                  OpenMode &~EFI_FILE_MODE_CREATE,\r
+                                  Attributes\r
+                                 );\r
+            //\r
+            // if above failed now open and create the 'item'\r
+            // if OpenMode EFI_FILE_MODE_CREATE bit was on (but disabled above)\r
+            //\r
+            if ((EFI_ERROR (Status)) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)) {\r
+              Status = Handle2->Open (\r
+                                    Handle2,\r
+                                    &Handle1,\r
+                                    AlignedNode->PathName,\r
+                                    OpenMode,\r
+                                    Attributes\r
+                                   );\r
+            }\r
           }\r
           }\r
-        }\r
-        //\r
-        // Close the last node\r
-        //\r
-        ShellInfoObject.NewEfiShellProtocol->CloseFile (Handle2);\r
+          //\r
+          // Close the last node\r
+          //\r
+          ShellInfoObject.NewEfiShellProtocol->CloseFile (Handle2);\r
 \r
 \r
-        //\r
-        // If there's been an error, stop\r
-        //\r
-        if (EFI_ERROR (Status)) {\r
-          break;\r
-        }\r
-      } // for loop\r
+          //\r
+          // If there's been an error, stop\r
+          //\r
+          if (EFI_ERROR (Status)) {\r
+            break;\r
+          }\r
+        } // for loop\r
+      }\r
     }\r
   }\r
   SHELL_FREE_NON_NULL(AlignedNode);\r
     }\r
   }\r
   SHELL_FREE_NON_NULL(AlignedNode);\r
@@ -2001,7 +2003,7 @@ ShellSearchHandle(
               ShellInfoNode->FullName = NewFullName;\r
             }\r
           }\r
               ShellInfoNode->FullName = NewFullName;\r
             }\r
           }\r
-          if (Directory && !EFI_ERROR(Status)){\r
+          if (Directory && !EFI_ERROR(Status) && ShellInfoNode->FullName != NULL && ShellInfoNode->FileName != NULL){\r
             //\r
             // should be a directory\r
             //\r
             //\r
             // should be a directory\r
             //\r
@@ -2015,7 +2017,6 @@ ShellSearchHandle(
               //\r
               //\r
               //\r
               //\r
               //\r
               //\r
-              ASSERT_EFI_ERROR(Status);\r
               if (EFI_ERROR(Status)) {\r
                 break;\r
               }\r
               if (EFI_ERROR(Status)) {\r
                 break;\r
               }\r
index ccfa0b065478821938d33e0593adc6e3cd082691..d74a47ba52585f2a95355fbb58f34bf22af0e4c4 100644 (file)
@@ -679,18 +679,19 @@ PerformMappingDelete(
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-  //\r
-  // Get the map name(s) for each one.\r
-  //\r
-  for ( LoopVar = 0\r
-      ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
-      ; LoopVar ++\r
-     ){\r
-    if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {\r
-        Deleted = TRUE;\r
+  if (HandleBuffer != NULL) {\r
+    //\r
+    // Get the map name(s) for each one.\r
+    //\r
+    for ( LoopVar = 0\r
+        ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
+        ; LoopVar ++\r
+       ){\r
+      if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {\r
+          Deleted = TRUE;\r
+      }\r
     }\r
   }\r
     }\r
   }\r
-\r
   //\r
   // Look up all BlockIo in the platform\r
   //\r
   //\r
   // Look up all BlockIo in the platform\r
   //\r
@@ -718,30 +719,32 @@ PerformMappingDelete(
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-  //\r
-  // Get the map name(s) for each one.\r
-  //\r
-  for ( LoopVar = 0\r
-      ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
-      ; LoopVar ++\r
-     ){\r
+  if (HandleBuffer != NULL) {\r
     //\r
     //\r
-    // Skip any that were already done...\r
+    // Get the map name(s) for each one.\r
     //\r
     //\r
-    if (gBS->OpenProtocol(\r
-      HandleBuffer[LoopVar],\r
-      &gEfiDevicePathProtocolGuid,\r
-      NULL,\r
-      gImageHandle,\r
-      NULL,\r
-      EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {\r
-        continue;\r
-    }\r
-    if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {\r
-        Deleted = TRUE;\r
+    for ( LoopVar = 0\r
+        ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
+        ; LoopVar ++\r
+       ){\r
+      //\r
+      // Skip any that were already done...\r
+      //\r
+      if (gBS->OpenProtocol(\r
+        HandleBuffer[LoopVar],\r
+        &gEfiDevicePathProtocolGuid,\r
+        NULL,\r
+        gImageHandle,\r
+        NULL,\r
+        EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {\r
+          continue;\r
+      }\r
+      if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {\r
+          Deleted = TRUE;\r
+      }\r
     }\r
   }\r
     }\r
   }\r
-  FreePool(HandleBuffer);\r
+  SHELL_FREE_NON_NULL(HandleBuffer);\r
   if (!Deleted) {\r
     return (EFI_NOT_FOUND);\r
   }\r
   if (!Deleted) {\r
     return (EFI_NOT_FOUND);\r
   }\r