added 3 changesets to branch 'refs/remotes/pdziepak-github/nfs4' old head: 8f57d30ea4934abc215ae850fa3612474087d7a3 new head: ea70f0aa5c59adccf140ab6bd278ae23d9eff5c6 ---------------------------------------------------------------------------- 085c6e2: nfs4: Fix double free at unmounting 7ef9380: nfs4: Fix several problems with IdMapper error handling ea70f0a: nfs4: Fix error handling problems in FileInfo::UpdateFileHandles() [ Pawel Dziepak <pdziepak@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 53 insertions(+), 28 deletions(-) src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp | 27 +++++++--- src/add-ons/kernel/file_systems/nfs4/IdMap.cpp | 9 ++-- src/add-ons/kernel/file_systems/nfs4/Inode.cpp | 1 - .../kernel/file_systems/nfs4/idmapper/IdMapper.cpp | 44 ++++++++++------ ############################################################################ Commit: 085c6e2d99dede3cc2e2b9631040201e2a8d78d7 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Wed Jul 4 13:45:08 2012 UTC nfs4: Fix double free at unmounting ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp index 055b6b2..a572536 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Inode.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/Inode.cpp @@ -96,7 +96,6 @@ Inode::CreateInode(Filesystem* fs, const FileInfo &fi, Inode** _inode) Inode::~Inode() { - free(const_cast<char*>(fInfo.fName)); } ############################################################################ Commit: 7ef9380fb3f606dd61b82905ab1247765546817c Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Wed Jul 4 14:23:04 2012 UTC nfs4: Fix several problems with IdMapper error handling ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/IdMap.cpp b/src/add-ons/kernel/file_systems/nfs4/IdMap.cpp index 37d7559..9a02f8b 100644 --- a/src/add-ons/kernel/file_systems/nfs4/IdMap.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/IdMap.cpp @@ -89,8 +89,8 @@ IdMap::_GetValue(const char* buffer, int32 code) if (code != MsgReply) return 0; - else - return value; + + return value; } while (true); } @@ -135,8 +135,9 @@ IdMap::_GetBuffer(T value, int32 code) if (code != MsgReply) { free(buffer); return NULL; - } else - return buffer; + } + + return buffer; } while (true); } diff --git a/src/add-ons/kernel/file_systems/nfs4/idmapper/IdMapper.cpp b/src/add-ons/kernel/file_systems/nfs4/idmapper/IdMapper.cpp index a0d6c49..5c8d2a9 100644 --- a/src/add-ons/kernel/file_systems/nfs4/idmapper/IdMapper.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/idmapper/IdMapper.cpp @@ -62,6 +62,8 @@ AddDomain(const char* name) { uint32 fullLength = strlen(name) + strlen(gDomainName) + 2; char* fullName = reinterpret_cast<char*>(malloc(fullLength)); + if (fullName == NULL) + return NULL; strcpy(fullName, name); strcat(fullName, "@"); @@ -93,17 +95,23 @@ UIDToName(void* buffer) { uid_t userId = *reinterpret_cast<uid_t*>(buffer); - const char* fullName = kNobodyName; + const char* name = NULL; struct passwd* userInfo = getpwuid(userId); if (userInfo != NULL) { - const char* name = userInfo->pw_name; - fullName = AddDomain(name); + name = userInfo->pw_name; + name = AddDomain(name); } - status_t result = write_port(gReplyPort, MsgReply, fullName, - strlen(fullName) + 1); - free(const_cast<char*>(fullName)); + status_t result; + + if (name != NULL) { + result = write_port(gReplyPort, MsgReply, name, strlen(name) + 1); + free(const_cast<char*>(name)); + } else { + result = write_port(gReplyPort, MsgReply, kNobodyName, + strlen(kNobodyName) + 1); + } return result; } @@ -133,17 +141,23 @@ GIDToName(void* buffer) { gid_t groupId = *reinterpret_cast<gid_t*>(buffer); - const char* fullName = kNogroupName; + const char* name = NULL; struct group* groupInfo = getgrgid(groupId); if (groupInfo != NULL) { - const char* name = groupInfo->gr_name; - fullName = AddDomain(name); + name = groupInfo->gr_name; + name = AddDomain(name); } - status_t result = write_port(gReplyPort, MsgReply, fullName, - strlen(fullName) + 1); - free(const_cast<char*>(fullName)); + status_t result; + + if (name != NULL) { + result = write_port(gReplyPort, MsgReply, name, strlen(name) + 1); + free(const_cast<char*>(name)); + } else { + result = write_port(gReplyPort, MsgReply, kNogroupName, + strlen(kNogroupName) + 1); + } return result; } @@ -193,7 +207,7 @@ MainLoop() result = ParseRequest(code, buffer); free(buffer); - if (result == B_BAD_PORT_ID) + if (result != B_OK) return 0; } while (true); @@ -236,13 +250,13 @@ int main(int argc, char** argv) { gRequestPort = find_port(kRequestPortName); - if (gRequestPort == B_NAME_NOT_FOUND) { + if (gRequestPort < B_OK) { fprintf(stderr, "%s\n", strerror(gRequestPort)); return gRequestPort; } gReplyPort = find_port(kReplyPortName); - if (gReplyPort == B_NAME_NOT_FOUND) { + if (gReplyPort < B_OK) { fprintf(stderr, "%s\n", strerror(gReplyPort)); return gReplyPort; } ############################################################################ Commit: ea70f0aa5c59adccf140ab6bd278ae23d9eff5c6 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Wed Jul 4 14:30:21 2012 UTC nfs4: Fix error handling problems in FileInfo::UpdateFileHandles() ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp b/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp index 1ec4daa..4838fa4 100644 --- a/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/FileInfo.cpp @@ -14,13 +14,17 @@ static status_t -sParsePath(RequestBuilder& req, uint32* count, const char* _path) +ParsePath(RequestBuilder& req, uint32& count, const char* _path) { char* path = strdup(_path); + if (path == NULL) + return B_NO_MEMORY; + char* pathStart = path; char* pathEnd; + while (pathStart != NULL) { - pathEnd = strpbrk(pathStart, "/"); + pathEnd = strchr(pathStart, '/'); if (pathEnd != NULL) *pathEnd = '\0'; @@ -31,7 +35,7 @@ sParsePath(RequestBuilder& req, uint32* count, const char* _path) else pathStart = NULL; - (*count)++; + count++; } free(path); @@ -48,9 +52,15 @@ FileInfo::UpdateFileHandles(Filesystem* fs) req.PutRootFH(); uint32 lookupCount = 0; + status_t result; - sParsePath(req, &lookupCount, fs->Path()); - sParsePath(req, &lookupCount, fPath); + result = ParsePath(req, lookupCount, fs->Path()); + if (result != B_OK) + return result; + + result = ParsePath(req, lookupCount, fPath); + if (result != B_OK) + return result; if (fs->IsAttrSupported(FATTR4_FILEID)) { AttrValue attr; @@ -64,7 +74,7 @@ FileInfo::UpdateFileHandles(Filesystem* fs) req.LookUpUp(); req.GetFH(); - status_t result = request.Send(); + result = request.Send(); if (result != B_OK) return result; @@ -84,7 +94,8 @@ FileInfo::UpdateFileHandles(Filesystem* fs) if (reply.LookUpUp() == B_ENTRY_NOT_FOUND) { fParent = fHandle; return B_OK; - } else - return reply.GetFH(&fParent); + } + + return reply.GetFH(&fParent); }