]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellProtocol.c
fixes for NULL verification.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
index 0f799786ee3fb28aa571a8d1a564d8c0b9154de7..19759cbb2bbbf5194a887f782b759818d9d7768d 100644 (file)
@@ -907,75 +907,46 @@ InternalOpenFileDevicePath(
 \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
-      // 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
-      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
-        // 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
-        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
-          //  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
+          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 without letting it create\r
-          // prevents error on existing files/directories\r
+          // Open this file path node\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
-          // 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
-          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
@@ -983,20 +954,51 @@ InternalOpenFileDevicePath(
                                   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
-        // 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
-        // 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
@@ -2001,7 +2003,7 @@ ShellSearchHandle(
               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
@@ -2015,7 +2017,6 @@ ShellSearchHandle(
               //\r
               //\r
               //\r
-              ASSERT_EFI_ERROR(Status);\r
               if (EFI_ERROR(Status)) {\r
                 break;\r
               }\r