From 2dc729f17a45a4699a099a219ee18124904f94fa Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 9 Jul 2016 15:19:31 -0700 Subject: [PATCH] VFS: VFileFromFD should not open directories --- CHANGES | 1 + src/util/vfs/vfs-fd.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index 09405880c..d98741f8b 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,7 @@ Bugfixes: - GBA BIOS: Fix ArcTan2 accuracy and boundary conditions - SDL: Fix sporadic crash when deinitializing audio - GBA Audio: Reset audio FIFO DMA if an invalid destination is set + - VFS: VFileFromFD should not open directories Misc: - GBA: Slightly optimize GBAProcessEvents - Qt: Add preset for DualShock 4 diff --git a/src/util/vfs/vfs-fd.c b/src/util/vfs/vfs-fd.c index ec8abfb09..5b96f58b5 100644 --- a/src/util/vfs/vfs-fd.c +++ b/src/util/vfs/vfs-fd.c @@ -52,6 +52,12 @@ struct VFile* VFileFromFD(int fd) { return 0; } + struct stat stat; + if (fstat(fd, &stat) < 0 || S_ISDIR(stat.st_mode)) { + close(fd); + return 0; + } + struct VFileFD* vfd = malloc(sizeof(struct VFileFD)); if (!vfd) { return 0;