summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/dirent.cpp
diff options
context:
space:
mode:
authorMichel Hermier <michel.hermier@gmail.com>2022-01-12 02:55:09 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-16 11:18:04 +0100
commitadfdb63e0207afdb43a9d7e505502ee544ce7ab5 (patch)
treef3b131d77e63a8a8969b7f929456cf19cda15236 /Userland/Libraries/LibC/dirent.cpp
parent1af072e0f39d25e6f4016dd524b97291ea18eaee (diff)
downloadserenity-adfdb63e0207afdb43a9d7e505502ee544ce7ab5.zip
LibC: Fix `scandir` not checking for allocation failure
Diffstat (limited to 'Userland/Libraries/LibC/dirent.cpp')
-rw-r--r--Userland/Libraries/LibC/dirent.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/dirent.cpp b/Userland/Libraries/LibC/dirent.cpp
index fe902a32ce..35d6ce394b 100644
--- a/Userland/Libraries/LibC/dirent.cpp
+++ b/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];
}