瀏覽代碼

Kernel: Don't allow open() with (O_CREAT | O_DIRECTORY)

Andreas Kling 5 年之前
父節點
當前提交
064e46e581
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      Kernel/FileSystem/VirtualFileSystem.cpp

+ 3 - 0
Kernel/FileSystem/VirtualFileSystem.cpp

@@ -185,6 +185,9 @@ KResultOr<InodeMetadata> VFS::lookup_metadata(StringView path, Custody& base, in
 
 KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
 {
+    if ((options & O_CREAT) && (options & O_DIRECTORY))
+        return KResult(-EINVAL);
+
     RefPtr<Custody> parent_custody;
     auto custody_or_error = resolve_path(path, base, &parent_custody, options);
     if (options & O_CREAT) {