From 299279610c0354caf0cdf83dc0760b5c53e4dc01 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 9 Feb 2020 18:22:57 -0500 Subject: [PATCH] kernel/vfs: Add some missing initializations and BStackOrHeapArray. Part of #14961. --- src/system/kernel/fs/vfs.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index c75b643446..493971bb3d 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -8987,7 +8988,7 @@ _user_get_next_fd_info(team_id team, uint32* userCookie, fd_info* userInfo, struct fd_info info; uint32 cookie; - // only root can do this (or should root's group be enough?) + // only root can do this if (geteuid() != 0) return B_NOT_ALLOWED; @@ -9640,7 +9641,7 @@ status_t _user_read_stat(int fd, const char* userPath, bool traverseLink, struct stat* userStat, size_t statSize) { - struct stat stat; + struct stat stat = {0}; status_t status; if (statSize > sizeof(struct stat)) @@ -9969,7 +9970,7 @@ status_t _user_read_index_stat(dev_t device, const char* userName, struct stat* userStat) { char name[B_FILE_NAME_LENGTH]; - struct stat stat; + struct stat stat = {0}; status_t status; if (!IS_USER_ADDRESS(userName) || !IS_USER_ADDRESS(userStat)) @@ -10102,8 +10103,6 @@ int _user_open_query(dev_t device, const char* userQuery, size_t queryLength, uint32 flags, port_id port, int32 token) { - char* query; - if (device < 0 || userQuery == NULL || queryLength == 0) return B_BAD_VALUE; @@ -10114,18 +10113,14 @@ _user_open_query(dev_t device, const char* userQuery, size_t queryLength, if (queryLength >= 65536) return B_NAME_TOO_LONG; - query = (char*)malloc(queryLength + 1); - if (query == NULL) + BStackOrHeapArray query(queryLength); + if (!query.IsValid()) return B_NO_MEMORY; - if (user_strlcpy(query, userQuery, queryLength + 1) < B_OK) { - free(query); + + if (user_strlcpy(query, userQuery, queryLength + 1) < B_OK) return B_BAD_ADDRESS; - } - int fd = query_open(device, query, flags, port, token, false); - - free(query); - return fd; + return query_open(device, query, flags, port, token, false); }