hrev45384 adds 9 changesets to branch 'master' old head: 6e8749b27f2037e989d01a69b1c335ca45c8800f new head: 246c199c405c382ff1260fc30c8ab48b992a2a5c overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=246c199+%5E6e8749b ---------------------------------------------------------------------------- 62e4354: nfs4: Fix wrong parenthesising in ReplyInterpreter::_FlattenPathname This patch solves CID 990966. e975b31: nfs4: Ensure that a string is NULL terminated after strncpy() This fixes CID 990971. c689b9f: nfs4: Fix CID 990984 and 991173: missing assignment in error check a43c0e5: nfs4: Fix error checking in NFS4Server::_Renewal() This fixes CID 990985. 271d154: nfs4: Do not rely on implementation defined casting uint32 to int32 This solves CID 991172. b42b242: nfs4: Fix CID 991174: improve error checking in NFS4Inode::OpenFile() b0e5bfe: nfs4: Fix CID 991246: use name of the old entry when reporting removal f73dd62: nfs4: Fix CID 991294: error handling issues in Auth::CreateSys() 246c199: nfs4: Fix memory leaks in case of error in ReplyInterpreter::_DecodeAttrs() This patch fixes CID 991505, 991504, 991502, 991500, 991499, 991496. [ Pawel Dziepak <pdziepak@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- 9 files changed, 43 insertions(+), 31 deletions(-) .../kernel/file_systems/nfs4/Connection.cpp | 2 +- .../kernel/file_systems/nfs4/DirectoryCache.cpp | 2 +- .../kernel/file_systems/nfs4/InodeDir.cpp | 2 +- .../kernel/file_systems/nfs4/NFS4Inode.cpp | 13 ++++----- .../kernel/file_systems/nfs4/NFS4Server.cpp | 6 +++-- src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp | 16 ++++++----- .../file_systems/nfs4/ReplyInterpreter.cpp | 28 +++++++++++--------- .../kernel/file_systems/nfs4/ReplyInterpreter.h | 2 ++ .../kernel/file_systems/nfs4/RootInode.cpp | 3 ++- ############################################################################ Commit: 62e43541d730ae689710dbe1ddcd022866d67e72 URL: http://cgit.haiku-os.org/haiku/commit/?id=62e4354 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Mon Mar 18 23:33:46 2013 UTC nfs4: Fix wrong parenthesising in ReplyInterpreter::_FlattenPathname This patch solves CID 990966. ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp index 1dbcd8d..644460e 100644 --- a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp @@ -522,17 +522,17 @@ ReplyInterpreter::Write(uint32* size) } -static const char* -sFlattenPathname(XDR::ReadStream& str) +const char* +ReplyInterpreter::_FlattenPathname(XDR::ReadStream& stream) { - uint32 count = str.GetUInt(); + uint32 count = stream.GetUInt(); char* pathname = NULL; uint32 size = 0; for (uint32 i = 0; i < count; i++) { - const char* path = str.GetString(); + const char* path = stream.GetString(); size += strlen(path) + 1; if (pathname == NULL) { - pathname = reinterpret_cast<char*>(malloc(strlen(path + 1))); + pathname = reinterpret_cast<char*>(malloc(strlen(path) + 1)); pathname[0] = '\0'; } else { *pathname++ = '/'; @@ -657,11 +657,11 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, values[current].fAttribute = FATTR4_FS_LOCATIONS; FSLocations* locs = new FSLocations; - locs->fRootPath = sFlattenPathname(stream); + locs->fRootPath = _FlattenPathname(stream); locs->fCount = stream.GetUInt(); locs->fLocations = new FSLocation[locs->fCount]; for (uint32 i = 0; i < locs->fCount; i++) { - locs->fLocations[i].fRootPath = sFlattenPathname(stream); + locs->fLocations[i].fRootPath = _FlattenPathname(stream); locs->fLocations[i].fCount = stream.GetUInt(); locs->fLocations[i].fLocations = new const char*[locs->fLocations[i].fCount]; diff --git a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.h b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.h index b630b8f..654963a 100644 --- a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.h +++ b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.h @@ -108,6 +108,8 @@ public: private: void _ParseHeader(); + static const char* _FlattenPathname(XDR::ReadStream& stream); + status_t _DecodeAttrs(XDR::ReadStream& stream, AttrValue** attrs, uint32* count); status_t _OperationError(Opcode op); ############################################################################ Commit: e975b31db334fa84e61d3c59228eb72660759f0d URL: http://cgit.haiku-os.org/haiku/commit/?id=e975b31 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Mon Mar 18 23:36:49 2013 UTC nfs4: Ensure that a string is NULL terminated after strncpy() This fixes CID 990971. ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp b/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp index a215d6b..5278cf8 100644 --- a/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/RootInode.cpp @@ -135,7 +135,8 @@ RootInode::_UpdateInfo(bool force) || fFileSystem->GetConfiguration().fEmulateNamedAttrs) fInfoCache.flags |= B_FS_HAS_MIME | B_FS_HAS_ATTR; - strncpy(fInfoCache.volume_name, fName, B_FILE_NAME_LENGTH); + strncpy(fInfoCache.volume_name, fName, sizeof(fInfoCache.volume_name)); + fInfoCache.volume_name[sizeof(fInfoCache.volume_name) - 1] = '\0'; fInfoCacheExpire = time(NULL) + MetadataCache::kExpirationTime; ############################################################################ Commit: c689b9f5f144eb53acbea56b83af1e99274d48e4 URL: http://cgit.haiku-os.org/haiku/commit/?id=c689b9f Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Mon Mar 18 23:39:24 2013 UTC nfs4: Fix CID 990984 and 991173: missing assignment in error check ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp b/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp index 1b38517..0ea69d0 100644 --- a/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/InodeDir.cpp @@ -181,7 +181,7 @@ Inode::ReadDirUp(struct dirent* de, uint32 pos, uint32 size) if (fFileSystem->IsAttrSupported(FATTR4_FILEID)) { AttrValue* values; uint32 count; - reply.GetAttr(&values, &count); + result = reply.GetAttr(&values, &count); if (result != B_OK) return result; ############################################################################ Commit: a43c0e5ce0e2e7039b9397c51a574d221e9a6fed URL: http://cgit.haiku-os.org/haiku/commit/?id=a43c0e5 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Mon Mar 18 23:44:13 2013 UTC nfs4: Fix error checking in NFS4Server::_Renewal() This fixes CID 990985. ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/NFS4Server.cpp b/src/add-ons/kernel/file_systems/nfs4/NFS4Server.cpp index e92ede7..830935f 100644 --- a/src/add-ons/kernel/file_systems/nfs4/NFS4Server.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/NFS4Server.cpp @@ -229,7 +229,7 @@ NFS4Server::_Renewal() if (result != B_TIMED_OUT) { if (result == B_OK) release_sem(fWaitCancel); - return B_OK; + return result; } uint64 clientId = fClientId; @@ -244,7 +244,9 @@ NFS4Server::_Renewal() Request request(fServer, NULL); request.Builder().Renew(clientId); - request.Send(); + result = request.Send(); + if (result != B_OK) + continue; switch (request.Reply().NFS4Error()) { case NFS4ERR_CB_PATH_DOWN: ############################################################################ Commit: 271d1540b10d973aa59aa08a715f451487d04479 URL: http://cgit.haiku-os.org/haiku/commit/?id=271d154 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Mon Mar 18 23:58:15 2013 UTC nfs4: Do not rely on implementation defined casting uint32 to int32 This solves CID 991172. ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/Connection.cpp b/src/add-ons/kernel/file_systems/nfs4/Connection.cpp index 937e45e..5994b51 100644 --- a/src/add-ons/kernel/file_systems/nfs4/Connection.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/Connection.cpp @@ -477,7 +477,7 @@ ConnectionStream::Receive(void** _buffer, uint32* _size) record_size = ntohl(record_size); ASSERT(record_size > 0); - last_one = static_cast<int32>(record_size) < 0; + last_one = (record_size & LAST_FRAGMENT) != 0; record_size &= LAST_FRAGMENT - 1; void* ptr = realloc(buffer, size + record_size); ############################################################################ Commit: b42b242f62894fba406f4736fd462fbac2115744 URL: http://cgit.haiku-os.org/haiku/commit/?id=b42b242 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Tue Mar 19 00:11:20 2013 UTC nfs4: Fix CID 991174: improve error checking in NFS4Inode::OpenFile() ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp b/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp index 6118c42..56c226b 100644 --- a/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/NFS4Inode.cpp @@ -609,10 +609,8 @@ NFS4Inode::OpenFile(OpenState* state, int mode, OpenDelegationData* delegation) } result = reply.Verify(); - if (result != B_OK) { + if (result != B_OK) fFileSystem->OpenOwnerSequenceUnlock(sequence); - return result; - } if (result != B_OK && reply.NFS4Error() == NFS4ERR_NOT_SAME) return B_ENTRY_NOT_FOUND; @@ -623,10 +621,13 @@ NFS4Inode::OpenFile(OpenState* state, int mode, OpenDelegationData* delegation) reply.PutFH(); result = reply.Open(state->fStateID, &state->fStateSeq, &confirm, delegation); + if (result != B_OK) { + fFileSystem->OpenOwnerSequenceUnlock(sequence); + return result; + } FileHandle handle; - reply.GetFH(&handle); - + result = reply.GetFH(&handle); if (result != B_OK) { fFileSystem->OpenOwnerSequenceUnlock(sequence); return result; @@ -638,7 +639,7 @@ NFS4Inode::OpenFile(OpenState* state, int mode, OpenDelegationData* delegation) state->fOpened = true; if (confirm) - result = ConfirmOpen(fInfo.fHandle, state, &sequence); + result = ConfirmOpen(fInfo.fHandle, state, &sequence); fFileSystem->OpenOwnerSequenceUnlock(sequence); return result; ############################################################################ Commit: b0e5bfeab52f88aefd73ebd22787edea05c7d3ca URL: http://cgit.haiku-os.org/haiku/commit/?id=b0e5bfe Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Tue Mar 19 00:15:27 2013 UTC nfs4: Fix CID 991246: use name of the old entry when reporting removal ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp b/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp index c40707a..577a8a7 100644 --- a/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/DirectoryCache.cpp @@ -334,7 +334,7 @@ DirectoryCache::NotifyChanges(DirectoryCacheSnapshot* oldSnapshot, while (oldCurrent != NULL) { if (fAttrDir) { notify_attribute_changed(fInode->GetFileSystem()->DevId(), - fInode->ID(), newCurrent->fName, B_ATTR_REMOVED); + fInode->ID(), oldCurrent->fName, B_ATTR_REMOVED); } else { notify_entry_removed(fInode->GetFileSystem()->DevId(), fInode->ID(), oldCurrent->fName, oldCurrent->fNode); ############################################################################ Commit: f73dd62491f3a31751e21c057b3bccef64ca65d5 URL: http://cgit.haiku-os.org/haiku/commit/?id=f73dd62 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Tue Mar 19 00:23:01 2013 UTC nfs4: Fix CID 991294: error handling issues in Auth::CreateSys() ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp b/src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp index b10f2ab..9164c87 100644 --- a/src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp @@ -13,6 +13,7 @@ #include <stdlib.h> #include <unistd.h> +#include <AutoDeleter.h> #include <SupportDefs.h> #include <util/kernel_cpp.h> @@ -51,6 +52,7 @@ Auth::CreateSys() Auth* auth = new(std::nothrow) Auth; if (auth == NULL) return NULL; + ObjectDeleter<Auth> authDeleter(auth); XDR::WriteStream xdr; xdr.AddUInt(time(NULL)); @@ -64,7 +66,12 @@ Auth::CreateSys() xdr.AddUInt(getgid()); int count = getgroups(0, NULL); + if (count < B_OK) + return NULL; gid_t* groups = (gid_t*)malloc(count * sizeof(gid_t)); + if (groups == NULL) + return NULL; + int len = getgroups(count, groups); if (len > 0) { len = min_c(len, 16); @@ -74,18 +81,15 @@ Auth::CreateSys() } else xdr.AddUInt(0); free(groups); - if (xdr.Error() != B_OK) { - delete auth; + if (xdr.Error() != B_OK) return NULL; - } auth->fStream.AddInt(AUTH_SYS); auth->fStream.AddOpaque(xdr); - if (auth->fStream.Error() != B_OK) { - delete auth; + if (auth->fStream.Error() != B_OK) return NULL; - } + authDeleter.Detach(); return auth; } ############################################################################ Revision: hrev45384 Commit: 246c199c405c382ff1260fc30c8ab48b992a2a5c URL: http://cgit.haiku-os.org/haiku/commit/?id=246c199 Author: Pawel Dziepak <pdziepak@xxxxxxxxxxx> Date: Tue Mar 19 00:34:22 2013 UTC nfs4: Fix memory leaks in case of error in ReplyInterpreter::_DecodeAttrs() This patch fixes CID 991505, 991504, 991502, 991500, 991499, 991496. ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp index 644460e..e13808c 100644 --- a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp @@ -11,6 +11,7 @@ #include <string.h> +#include <AutoDeleter.h> #include <util/kernel_cpp.h> #include "Cookie.h" @@ -554,6 +555,7 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, uint32* bitmap = new(std::nothrow) uint32[bcount]; if (bitmap == NULL) return B_NO_MEMORY; + ArrayDeleter<uint32> _(bitmap); uint32 attr_count = 0; for (uint32 i = 0; i < bcount; i++) { @@ -573,10 +575,8 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, XDR::ReadStream stream(const_cast<void*>(ptr), size); AttrValue* values = new(std::nothrow) AttrValue[attr_count]; - if (values == NULL) { - delete[] bitmap; + if (values == NULL) return B_NO_MEMORY; - } uint32 current = 0; @@ -774,11 +774,13 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, current++; } - delete[] bitmap; - *count = attr_count; *attrs = values; - return str.IsEOF() ? B_BAD_VALUE : B_OK; + if (str.IsEOF()) { + delete[] values; + return B_BAD_VALUE; + } + return B_OK; }