浏览代码

Fix null deref in contextSwitch().

Andreas Kling 6 年之前
父节点
当前提交
dd6706a1a1
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      Kernel/Task.cpp

+ 10 - 7
Kernel/Task.cpp

@@ -360,14 +360,17 @@ static bool contextSwitch(Task* t)
     if (current == t)
         return false;
 
-    // If the last task hasn't blocked (still marked as running),
-    // mark it as runnable for the next round.
-    if (current->state() == Task::Running)
-        current->setState(Task::Runnable);
+    if (current) {
+        // If the last task hasn't blocked (still marked as running),
+        // mark it as runnable for the next round.
+        if (current->state() == Task::Running)
+            current->setState(Task::Runnable);
 
-    bool success = MemoryManager::the().unmapRegionsForTask(*current);
-    ASSERT(success);
-    success = MemoryManager::the().mapRegionsForTask(*t);
+        bool success = MemoryManager::the().unmapRegionsForTask(*current);
+        ASSERT(success);
+    }
+
+    bool success = MemoryManager::the().mapRegionsForTask(*t);
     ASSERT(success);
 
     current = t;