浏览代码

LibC: Fix `scandir` not checking for allocation failure

Michel Hermier 3 年之前
父节点
当前提交
adfdb63e02
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      Userland/Libraries/LibC/dirent.cpp

+ 3 - 0
Userland/Libraries/LibC/dirent.cpp

@@ -278,6 +278,9 @@ int scandir(const char* dir_name,
 
     const int size = tmp_names.size();
     auto** names = static_cast<struct dirent**>(kmalloc_array(size, sizeof(struct dirent*)));
+    if (names == nullptr) {
+        return -1;
+    }
     for (auto i = 0; i < size; i++) {
         names[i] = tmp_names[i];
     }