From: Oliver Kurth Date: Mon, 9 Sep 2019 18:23:48 +0000 (-0700) Subject: More Coverity annotations for open-vm-tools issues. X-Git-Tag: stable-11.1.0~242 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6328953abbb54256fb356c428430f352519c0f14;p=thirdparty%2Fopen-vm-tools.git More Coverity annotations for open-vm-tools issues. Add annotations for additional Coverity-reported issues so that Coverity scans of ovt will automatically classify these issues as "intentional." Such annotations are useful both for internal use as well as for partners who run Coverity scans of open-vm-tools. --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServer.c b/open-vm-tools/lib/hgfsServer/hgfsServer.c index c404047f2..e140e420a 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServer.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServer.c @@ -3399,6 +3399,13 @@ HgfsServerSessionReceive(HgfsPacket *packet, // IN: Hgfs Packet LOG(4, ("Error %d occurred parsing the packet\n", (uint32)status)); HgfsServerCompleteRequest(status, 0, input); } + + /* + * Storage pointed at by the variable input was freed either by + * HgfsServerProcessRequest at the end of request processing + * or by HgfsServerCompleteRequest if there was a protocol error. + */ + /* coverity[leaked_storage] */ } diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index 980583303..f3e176a15 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -393,6 +393,13 @@ ProcMgr_ListProcesses(void) int exeLen; char exeRealPath[1024]; + /* + * This readlink() call on the "exe" file of the current /proc + * entry is not intended as a check on the subsequent open() of + * the "status" file of that entry, hence no time-of-check to + * time-of-use issue. + */ + /* coverity[fs_check_call] */ exeLen = readlink(cmdFilePath, exeRealPath, sizeof exeRealPath -1); if (exeLen != -1) { exeRealPath[exeLen] = '\0'; @@ -521,7 +528,13 @@ ProcMgr_ListProcesses(void) * stat() /proc/ to get the owner. We use fileStat.st_uid * later in this code. If we can't stat(), ignore and continue. * Maybe we don't have enough permission. + * + * This stat() call on the current /proc entry is not intended + * as a check on the open() near the top of the while loop which + * is on the cmdline file of the next entry in /proc, hence no + * time-of-check to time-of-use issue. */ + /* coverity[fs_check_call] */ statResult = stat(cmdFilePath, &fileStat); if (0 != statResult) { goto next_entry; diff --git a/open-vm-tools/lib/rpcChannel/rpcChannel.c b/open-vm-tools/lib/rpcChannel/rpcChannel.c index 98b46d196..7d1edbde4 100644 --- a/open-vm-tools/lib/rpcChannel/rpcChannel.c +++ b/open-vm-tools/lib/rpcChannel/rpcChannel.c @@ -296,6 +296,12 @@ RpcChannelXdrWrapper(RpcInData *data, if (!xdrProc(&xdrs, copy.result, 0)) { ret = RPCIN_SETRETVALS(data, "XDR serialization failed.", FALSE); + + /* + * DynXdr_Destroy only tries to free storage returned by a call to + * DynXdr_Create(NULL). + */ + /* coverity[address_free] */ DynXdr_Destroy(&xdrs, TRUE); goto exit; } @@ -306,6 +312,12 @@ RpcChannelXdrWrapper(RpcInData *data, data->result = DynXdr_Get(&xdrs); data->resultLen = XDR_GETPOS(&xdrs); data->freeResult = TRUE; + + /* + * DynXdr_Destroy only tries to free storage returned by a call to + * DynXdr_Create(NULL). + */ + /* coverity[address_free] */ DynXdr_Destroy(&xdrs, FALSE); } @@ -362,6 +374,12 @@ RpcChannel_BuildXdrCommand(const char *cmd, ret = TRUE; exit: + + /* + * DynXdr_Destroy only tries to free storage returned by a call to + * DynXdr_Create(NULL). + */ + /* coverity[address_free] */ DynXdr_Destroy(&xdrs, !ret); return ret; } diff --git a/open-vm-tools/libguestlib/vmGuestLib.c b/open-vm-tools/libguestlib/vmGuestLib.c index f3d485216..e7f779531 100644 --- a/open-vm-tools/libguestlib/vmGuestLib.c +++ b/open-vm-tools/libguestlib/vmGuestLib.c @@ -1842,6 +1842,12 @@ VMGuestLibIoctl(const GuestLibIoctlParam *param, } ret = RpcChannel_SendOneRaw(DynXdr_Get(&xdrs), xdr_getpos(&xdrs), reply, replySize); + + /* + * DynXdr_Destroy only tries to free storage returned by a call to + * DynXdr_Create(NULL). + */ + /* coverity[address_free] */ DynXdr_Destroy(&xdrs, TRUE); return ret; } diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c index f0df0e2e5..b28325048 100644 --- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c +++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c @@ -994,6 +994,12 @@ GuestInfoSendNicInfoXdr(ToolsAppCtx *ctx, // IN } vm_free(reply); } + + /* + * DynXdr_Destroy only tries to free storage returned by a call to + * DynXdr_Create(NULL). + */ + /* coverity[address_free] */ DynXdr_Destroy(&xdrs, TRUE); exit: diff --git a/open-vm-tools/toolbox/toolboxcmd-info.c b/open-vm-tools/toolbox/toolboxcmd-info.c index 910f20881..c7408d1fe 100644 --- a/open-vm-tools/toolbox/toolboxcmd-info.c +++ b/open-vm-tools/toolbox/toolboxcmd-info.c @@ -81,6 +81,12 @@ InfoSendNetworkXdr(GuestNicProto *message, } ToolsCmd_FreeRPC(reply); } + + /* + * DynXdr_Destroy only tries to free storage returned by a call to + * DynXdr_Create(NULL). + */ + /* coverity[address_free] */ DynXdr_Destroy(&xdrs, TRUE); exit: diff --git a/open-vm-tools/vgauth/serviceImpl/alias.c b/open-vm-tools/vgauth/serviceImpl/alias.c index e719deff8..83694e876 100644 --- a/open-vm-tools/vgauth/serviceImpl/alias.c +++ b/open-vm-tools/vgauth/serviceImpl/alias.c @@ -675,6 +675,14 @@ ServiceLoadFileContentsPosix(const gchar *fileName, *fileSize = 0; *contents = NULL; + + /* + * No time-of-check to time-of-use issue between this lstat() call and the + * subsequent open() since the open() is followed by fstat() and a series + * of checks of the fstat results against the lstat results to ensure that + * key file attributes did not change between the lstat() and the open(). + */ + /* coverity[fs_check_call] */ ret = g_lstat(fileName, &lstatBuf); if (ret != 0) { Warning("%s: lstat(%s) failed (%d %d)\n",