From f73dd62491f3a31751e21c057b3bccef64ca65d5 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Tue, 19 Mar 2013 01:23:01 +0100 Subject: [PATCH] nfs4: Fix CID 991294: error handling issues in Auth::CreateSys() --- src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp b/src/add-ons/kernel/file_systems/nfs4/RPCAuth.cpp index b10f2abba0..9164c87b5d 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 #include +#include #include #include @@ -51,6 +52,7 @@ Auth::CreateSys() Auth* auth = new(std::nothrow) Auth; if (auth == NULL) return NULL; + ObjectDeleter 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; }