From 490e7c87e0378fb22eadfcc0c6d933db04206ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Mon, 12 Feb 2018 08:45:19 +0100 Subject: [PATCH] sys/vfs: Check suggested fd is valid Avoids out of bounds array access on _vfs_open_files if vfs_bind is called with an invalid (positive) fd number --- sys/vfs/vfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index 37db7479ef..9eb4c1d309 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -871,10 +871,10 @@ static inline int _allocate_fd(int fd) break; } } - if (fd >= VFS_MAX_OPEN_FILES) { - /* The _vfs_open_files array is full */ - return -ENFILE; - } + } + if (fd >= VFS_MAX_OPEN_FILES) { + /* The _vfs_open_files array is full */ + return -ENFILE; } else if (_vfs_open_files[fd].pid != KERNEL_PID_UNDEF) { /* The desired fd is already in use */