浏览代码

lib/misc: avoid NULL dereference in LibInsertToTailOfBootOrder

AllocatePool() may return NULL. We must check the return value before
dereferencing it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Heinrich Schuchardt 3 年之前
父节点
当前提交
500c10f191
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      lib/misc.c

+ 4 - 4
lib/misc.c

@@ -386,7 +386,9 @@ LibInsertToTailOfBootOrder (
 
     VarSize += sizeof(UINT16);
     NewBootOptionArray = AllocatePool (VarSize);
-    
+    if (!NewBootOptionArray)
+        return EFI_OUT_OF_RESOURCES;
+
     for (Index = 0; Index < ((VarSize/sizeof(UINT16)) - 1); Index++) {
         NewBootOptionArray[Index] = BootOptionArray[Index];
     }
@@ -403,9 +405,7 @@ LibInsertToTailOfBootOrder (
                 VarSize, (VOID*) NewBootOptionArray
                 );
 
-    if (NewBootOptionArray) {
-        FreePool (NewBootOptionArray);
-    }
+    FreePool (NewBootOptionArray);
     if (BootOptionArray) {
         FreePool (BootOptionArray);
     }