From cbb314348c85ea224eaa8548b2e2ea34beb7c69a Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 28 Oct 2019 16:12:42 -0700 Subject: [PATCH] Fix 'variable scope can be reduced' warnings. One of the code quality checkers (Codacy) reported the following issue for a bunch of files bundled in 'open-vm-tools'. """ Fix 'The scope of the variable 'var' can be reduced.' """ Checked all applicable files and removed the variable initialization where it's really not necessary. This is really not a major issue but it's no harm fixing. --- open-vm-tools/hgfsclient/hgfsclient.c | 14 ++++++------- open-vm-tools/lib/appUtil/appUtilX11.c | 10 ++++------ .../lib/asyncsocket/asyncSocketInterface.c | 4 +++- open-vm-tools/lib/dataMap/dataMap.c | 3 ++- open-vm-tools/lib/file/fileIO.c | 6 ++++-- open-vm-tools/lib/file/fileIOPosix.c | 5 ++--- open-vm-tools/lib/file/fileLockPrimitive.c | 5 +++-- open-vm-tools/lib/file/fileStandAlone.c | 2 +- open-vm-tools/lib/file/fileTempPosix.c | 6 ++---- open-vm-tools/lib/foundryMsg/foundryMsg.c | 10 +++++----- open-vm-tools/lib/glibUtils/fileLogger.c | 4 ++-- open-vm-tools/lib/hgfs/hgfsEscape.c | 6 +++--- open-vm-tools/lib/lock/ulExcl.c | 2 +- open-vm-tools/lib/misc/codesetOld.c | 6 ++++-- open-vm-tools/lib/misc/hostinfoPosix.c | 3 ++- open-vm-tools/lib/misc/machineID.c | 5 ++--- open-vm-tools/lib/misc/strutil.c | 5 +++-- open-vm-tools/lib/misc/util_misc.c | 3 ++- open-vm-tools/lib/nicInfo/nicInfoPosix.c | 9 +++++---- open-vm-tools/lib/rpcChannel/simpleSocket.c | 5 ++--- open-vm-tools/lib/rpcIn/rpcin.c | 3 +-- .../lib/unicode/unicodeSimpleTypes.c | 4 ++-- open-vm-tools/lib/user/util.c | 7 +++---- open-vm-tools/libDeployPkg/linuxDeployment.c | 4 ++-- open-vm-tools/libDeployPkg/processPosix.c | 6 +++--- open-vm-tools/modules/solaris/vmxnet/vmxnet.c | 20 +++++++++---------- .../modules/solaris/vmxnet3/vmxnet3_main.c | 2 -- .../modules/solaris/vmxnet3/vmxnet3_rx.c | 6 +++--- open-vm-tools/namespacetool/namespacetool.c | 7 +++++-- .../services/plugins/deployPkg/deployPkg.c | 13 ++++++------ .../plugins/dndcp/copyPasteCompatX11.c | 11 +++++----- .../services/plugins/dndcp/copyPasteUIX11.cpp | 3 ++- .../services/plugins/dndcp/dnd/dndMsg.c | 6 +++--- .../services/plugins/dndcp/dnd/dndXdg.c | 3 ++- .../services/plugins/dndcp/dndUIX11.cpp | 12 ++++++----- .../services/plugins/dndcp/pointer.cpp | 7 +++---- .../plugins/dndcp/vmCopyPasteDnDWrapper.cpp | 17 +++++++++------- .../plugins/guestInfo/guestInfoServer.c | 5 ++--- .../plugins/resolutionSet/resolutionRandR12.c | 9 ++++----- .../plugins/resolutionSet/resolutionX11.c | 14 +++++++------ .../services/plugins/vmbackup/scriptOps.c | 7 ++++--- open-vm-tools/services/vmtoolsd/toolsRpc.c | 2 +- .../tests/testVmblock/manual-blocker.c | 6 +++--- open-vm-tools/vgauth/service/fileLogger.c | 4 ++-- open-vm-tools/vgauth/service/gio.c | 13 ++++++------ open-vm-tools/vgauth/serviceImpl/alias.c | 3 ++- open-vm-tools/vgauth/serviceImpl/proto.c | 7 ++++--- open-vm-tools/vgauth/serviceImpl/verify.c | 9 +++------ open-vm-tools/vmblock-fuse/fsops.c | 11 +++++----- open-vm-tools/vmhgfs-fuse/cache.c | 3 ++- open-vm-tools/vmhgfs-fuse/file.c | 5 ++--- 51 files changed, 176 insertions(+), 166 deletions(-) diff --git a/open-vm-tools/hgfsclient/hgfsclient.c b/open-vm-tools/hgfsclient/hgfsclient.c index 8ba516c20..12b668253 100644 --- a/open-vm-tools/hgfsclient/hgfsclient.c +++ b/open-vm-tools/hgfsclient/hgfsclient.c @@ -259,32 +259,32 @@ HgfsClient_PrintShares(void) int offset = 0; char escapedName[PATH_MAX + 1]; HgfsHandle rootHandle; - HgfsFileName *fileName; if (!HgfsClient_Open(&rootHandle)) { return success; } while (TRUE) { - fileName = HgfsClient_Read(rootHandle, offset++); + HgfsFileName *fileName = HgfsClient_Read(rootHandle, offset++); + if (fileName == NULL) { break; } - + /* Are we done? */ if (fileName->length == 0) { success = TRUE; break; } - /* + /* * Escape this filename. If we get back a negative result, it means that * the escaped filename is too big, so skip this share. */ if (HgfsEscape_Do(fileName->name, fileName->length, sizeof escapedName, escapedName) < 0) { - continue; - } + continue; + } /* Skip "." and ".." which can be returned. */ if (strcmp(".", escapedName) == 0 || @@ -294,7 +294,7 @@ HgfsClient_PrintShares(void) printf("%s\n", escapedName); } - + if (!HgfsClient_Close(rootHandle)) { success = FALSE; } diff --git a/open-vm-tools/lib/appUtil/appUtilX11.c b/open-vm-tools/lib/appUtil/appUtilX11.c index bdc5a1a6a..1e2c94031 100644 --- a/open-vm-tools/lib/appUtil/appUtilX11.c +++ b/open-vm-tools/lib/appUtil/appUtilX11.c @@ -489,10 +489,6 @@ AppUtil_CollectIconArray(const char *iconName, // IN GdkPixbuf *pixbuf; int width; int height; - int x; - int y; - int rowstride; - guchar *pixels; ASSERT((nitems - i) >= 2); width = value[i]; @@ -500,8 +496,10 @@ AppUtil_CollectIconArray(const char *iconName, // IN i += 2; pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); if (pixbuf) { - pixels = gdk_pixbuf_get_pixels(pixbuf); - rowstride = gdk_pixbuf_get_rowstride(pixbuf); + int x; + int y; + int rowstride = gdk_pixbuf_get_rowstride(pixbuf); + guchar *pixels = gdk_pixbuf_get_pixels(pixbuf); for (y = 0; y < height; y++) { for (x = 0; x < width && i < nitems; x++, i++) { diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c b/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c index dd270a381..587e89f6b 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c +++ b/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c @@ -1733,9 +1733,11 @@ AsyncSocket_WaitForReadMultiple(AsyncSocket **asock, // IN int timeoutMS, // IN int *outIdx) // OUT { - int i; int ret; + if (numSock > 0 && VALID(asock[0], waitForReadMultiple)) { + int i; + for (i = 0; i < numSock; i++) { AsyncSocketLock(asock[i]); } diff --git a/open-vm-tools/lib/dataMap/dataMap.c b/open-vm-tools/lib/dataMap/dataMap.c index 067cfe05e..dd1fce96f 100644 --- a/open-vm-tools/lib/dataMap/dataMap.c +++ b/open-vm-tools/lib/dataMap/dataMap.c @@ -2453,7 +2453,6 @@ DataMap_ToString(const DataMap *that, // IN { ClientData clientData; char *buffPtr; - const char *truncStr = " DATA TRUNCATED!!!\n"; /* This API is for debugging only, so we use hard coded buffer size */ const int32 maxBuffSize = 10 * 1024; @@ -2496,6 +2495,8 @@ DataMap_ToString(const DataMap *that, // IN ASSERT(buffPtr + maxBuffSize >= clientData.buffer); if (clientData.result == DMERR_BUFFER_TOO_SMALL) { + const char truncStr[] = " DATA TRUNCATED!!!\n"; + ASSERT(maxBuffSize > strlen(truncStr)); Str_Strcpy(buffPtr + maxBuffSize - strlen(truncStr) - 1, truncStr, strlen(truncStr) + 1); diff --git a/open-vm-tools/lib/file/fileIO.c b/open-vm-tools/lib/file/fileIO.c index 9da068ba8..677e7944b 100644 --- a/open-vm-tools/lib/file/fileIO.c +++ b/open-vm-tools/lib/file/fileIO.c @@ -836,8 +836,6 @@ FileIO_AtomicUpdateEx(FileIODescriptor *newFD, // IN/OUT: file IO descriptor uint32 newAccess; FileIOResult status; FileIODescriptor tmpFD; -#else - int fd; #endif int savedErrno = 0; int ret = 0; @@ -909,6 +907,8 @@ FileIO_AtomicUpdateEx(FileIODescriptor *newFD, // IN/OUT: file IO descriptor */ if (savedErrno == ENOSYS || savedErrno == ENOTTY) { if (renameOnNFS) { + int fd; + /* * NFS allows renames of locked files, even if both files * are locked. The file lock follows the file handle, not @@ -1015,6 +1015,8 @@ swapdone: __FUNCTION__, newPath, currPath, errno); savedErrno = errno; } else { + int fd; + ret = TRUE; fd = newFD->posix; newFD->posix = currFD->posix; diff --git a/open-vm-tools/lib/file/fileIOPosix.c b/open-vm-tools/lib/file/fileIOPosix.c index b79560e62..e92f34cf2 100644 --- a/open-vm-tools/lib/file/fileIOPosix.c +++ b/open-vm-tools/lib/file/fileIOPosix.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2018 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -536,7 +536,6 @@ ProxyReceiveResults(int sock_fd, // IN: int err; struct iovec iov; struct msghdr msg; - struct cmsghdr *cmsg; uint8_t cmsgBuf[CMSG_SPACE(sizeof(int))]; iov.iov_base = recv_errno; @@ -561,7 +560,7 @@ ProxyReceiveResults(int sock_fd, // IN: if (msg.msg_controllen == 0) { *recv_fd = -1; } else { - cmsg = CMSG_FIRSTHDR(&msg); + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); if ((cmsg->cmsg_level == SOL_SOCKET) && (cmsg->cmsg_type == SCM_RIGHTS)) { diff --git a/open-vm-tools/lib/file/fileLockPrimitive.c b/open-vm-tools/lib/file/fileLockPrimitive.c index 2ade15c9b..9f0bdea07 100644 --- a/open-vm-tools/lib/file/fileLockPrimitive.c +++ b/open-vm-tools/lib/file/fileLockPrimitive.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2018 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -755,7 +755,6 @@ FileLockScanDirectory(const char *lockDir, // IN: LockValues *ptr; Bool myLockFile; LockValues memberValues; - char buffer[FILELOCK_DATA_SIZE]; if ((fileList[i] == NULL) || (*fileList[i] == 'E')) { @@ -769,6 +768,8 @@ FileLockScanDirectory(const char *lockDir, // IN: /* It's me! No need to read or validate anything. */ ptr = myValues; } else { + char buffer[FILELOCK_DATA_SIZE]; + /* It's not me! Attempt to extract the member values. */ err = FileLockMemberValues(lockDir, fileList[i], buffer, FILELOCK_DATA_SIZE, &memberValues); diff --git a/open-vm-tools/lib/file/fileStandAlone.c b/open-vm-tools/lib/file/fileStandAlone.c index df2641246..6d3cba21a 100644 --- a/open-vm-tools/lib/file/fileStandAlone.c +++ b/open-vm-tools/lib/file/fileStandAlone.c @@ -543,7 +543,6 @@ File_MapPathPrefix(const char *oldPath, // IN: size_t oldPathLen = strlen(oldPath); for (i = 0; i < numPrefixes; i++) { - char *newPath; char *oldPrefix; char *newPrefix; size_t oldPrefixLen; @@ -576,6 +575,7 @@ File_MapPathPrefix(const char *oldPath, // IN: (oldPath[oldPrefixLen] == '\0'))) { size_t newPrefixLen = strlen(newPrefix); size_t newPathLen = (oldPathLen - oldPrefixLen) + newPrefixLen; + char *newPath; ASSERT(newPathLen > 0); ASSERT(oldPathLen >= oldPrefixLen); diff --git a/open-vm-tools/lib/file/fileTempPosix.c b/open-vm-tools/lib/file/fileTempPosix.c index 2bd591319..097d1d499 100644 --- a/open-vm-tools/lib/file/fileTempPosix.c +++ b/open-vm-tools/lib/file/fileTempPosix.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2004-2018 VMware, Inc. All rights reserved. + * Copyright (C) 2004-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -78,10 +78,8 @@ static char * FileTryDir(const char *dirName) // IN: Is this a writable directory? { - char *edirName; - if (dirName != NULL) { - edirName = Util_ExpandString(dirName); + char *edirName = Util_ExpandString(dirName); if ((edirName != NULL) && FileIsWritableDir(edirName)) { return edirName; diff --git a/open-vm-tools/lib/foundryMsg/foundryMsg.c b/open-vm-tools/lib/foundryMsg/foundryMsg.c index 7704e4481..99d811a6b 100644 --- a/open-vm-tools/lib/foundryMsg/foundryMsg.c +++ b/open-vm-tools/lib/foundryMsg/foundryMsg.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2004-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2004-2016,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -20,8 +20,8 @@ * foundryMsg.c -- * * This is a library for formatting and parsing the messages sent - * between a foundry client and the VMX. It is a stand-alone library - * so it can be used by the VMX tree without also linking in the + * between a foundry client and the VMX. It is a stand-alone library + * so it can be used by the VMX tree without also linking in the * entire foundry client-side library. */ @@ -631,7 +631,6 @@ VixMsg_AllocRequestMsg(size_t msgHeaderAndBodyLength, // IN VixCommandRequestHeader *commandRequest = NULL; size_t providedCredentialLength = 0; size_t totalCredentialLength = 0; - char *destPtr; if ((VIX_USER_CREDENTIAL_NAME_PASSWORD == credentialType) || (VIX_USER_CREDENTIAL_HOST_CONFIG_SECRET == credentialType) @@ -692,7 +691,8 @@ VixMsg_AllocRequestMsg(size_t msgHeaderAndBodyLength, // IN || (VIX_USER_CREDENTIAL_TICKETED_SESSION == credentialType) || (VIX_USER_CREDENTIAL_SSPI == credentialType) || (VIX_USER_CREDENTIAL_SAML_BEARER_TOKEN == credentialType)) { - destPtr = (char *) commandRequest; + char *destPtr = (char *) commandRequest; + destPtr += commandRequest->commonHeader.headerLength; destPtr += commandRequest->commonHeader.bodyLength; if (NULL != credential) { diff --git a/open-vm-tools/lib/glibUtils/fileLogger.c b/open-vm-tools/lib/glibUtils/fileLogger.c index 4940928b8..ace171d1e 100644 --- a/open-vm-tools/lib/glibUtils/fileLogger.c +++ b/open-vm-tools/lib/glibUtils/fileLogger.c @@ -258,7 +258,6 @@ FileLoggerOpen(FileLogger *data) * will always be index "0"). When not rotating, "maxFiles" is 1, so we * always keep one backup. */ - gchar *log; guint id; GPtrArray *logfiles = g_ptr_array_new(); @@ -268,7 +267,8 @@ FileLoggerOpen(FileLogger *data) * file, which may or may not exist. */ for (id = 0; id < data->maxFiles; id++) { - log = FileLoggerGetPath(data, id); + gchar *log = FileLoggerGetPath(data, id); + g_ptr_array_add(logfiles, log); if (!g_file_test(log, G_FILE_TEST_IS_REGULAR)) { break; diff --git a/open-vm-tools/lib/hgfs/hgfsEscape.c b/open-vm-tools/lib/hgfs/hgfsEscape.c index 5166d799c..7921b08bc 100644 --- a/open-vm-tools/lib/hgfs/hgfsEscape.c +++ b/open-vm-tools/lib/hgfs/hgfsEscape.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2018 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -875,7 +875,6 @@ HgfsEscapeUndoComponent(char *bufIn, // IN: Characters to be unesc uint32 *unprocessedLength) // IN: Unprocessed characters // in the whole name { - size_t offset; size_t sizeIn; char* curOutBuffer; char* escapePointer; @@ -886,7 +885,8 @@ HgfsEscapeUndoComponent(char *bufIn, // IN: Characters to be unesc sizeIn = strlen(curOutBuffer); escapePointer = strchr(curOutBuffer, HGFS_ESCAPE_CHAR); while (escapePointer != NULL) { - offset = escapePointer - bufIn; + size_t offset = escapePointer - bufIn; + if (HgfsIsEscapeSequence(bufIn, offset, sizeIn)) { char* substitute = strchr(HGFS_SUBSTITUTE_CHARS, bufIn[offset - 1]); if (substitute != NULL) { diff --git a/open-vm-tools/lib/lock/ulExcl.c b/open-vm-tools/lib/lock/ulExcl.c index 27d16346a..a0ad1c923 100644 --- a/open-vm-tools/lib/lock/ulExcl.c +++ b/open-vm-tools/lib/lock/ulExcl.c @@ -451,7 +451,6 @@ MXUser_AcquireExclLock(MXUserExclLock *lock) // IN/OUT: if (vmx86_stats) { VmTimeType value = 0; - MXUserHeldStats *heldStats; MXUserAcquireStats *acquireStats; acquireStats = Atomic_ReadPtr(&lock->acquireStatsMem); @@ -461,6 +460,7 @@ MXUser_AcquireExclLock(MXUserExclLock *lock) // IN/OUT: if (LIKELY(acquireStats != NULL)) { MXUserHisto *histo; + MXUserHeldStats *heldStats; MXUserAcquisitionSample(&acquireStats->data, TRUE, value > acquireStats->data.contentionDurationFloor, diff --git a/open-vm-tools/lib/misc/codesetOld.c b/open-vm-tools/lib/misc/codesetOld.c index efd5aee02..7d5474c01 100644 --- a/open-vm-tools/lib/misc/codesetOld.c +++ b/open-vm-tools/lib/misc/codesetOld.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2017 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2017,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -758,11 +758,13 @@ CodeSetOld_GetCurrentCodeSet(void) if (!cachedCodeset) { char *gFilenameEncoding = getenv("G_FILENAME_ENCODING"); - char *p; if (gFilenameEncoding && *gFilenameEncoding) { + char *p; + gFilenameEncoding = Util_SafeStrdup(gFilenameEncoding); p = strchr(gFilenameEncoding, ','); + if (p) { *p = '\0'; } diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index e7ae9d257..3baee94f4 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -2962,10 +2962,11 @@ HostinfoGetCpuInfo(int nCpu, // IN: while (cpu <= nCpu && StdIO_ReadNextLine(f, &line, 0, NULL) == StdIO_Success) { char *s; - char *e; if ((s = strstr(line, name)) && (s = strchr(s, ':'))) { + char *e; + s++; e = s + strlen(s); diff --git a/open-vm-tools/lib/misc/machineID.c b/open-vm-tools/lib/misc/machineID.c index 5f1ba786a..92efa03e9 100644 --- a/open-vm-tools/lib/misc/machineID.c +++ b/open-vm-tools/lib/misc/machineID.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2017,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -322,7 +322,6 @@ static int ObtainHardwareID(uint64 *hardwareID) // OUT: { uint32 i; - struct ifaddrs *p; struct ifaddrs *ifp; // Attempt to get the list of networking interfaces @@ -337,7 +336,7 @@ ObtainHardwareID(uint64 *hardwareID) // OUT: // search through a "reasonable" number of interfaces for (i = 0, *hardwareID = 0; i < 8; i++) { - p = CheckEthernet(ifp, i); + struct ifaddrs *p = CheckEthernet(ifp, i); if (p != NULL) { memcpy(hardwareID, LLADDR((struct sockaddr_dl *)p->ifa_addr), ETHER_ADDR_LEN); diff --git a/open-vm-tools/lib/misc/strutil.c b/open-vm-tools/lib/misc/strutil.c index 70737bd1a..5ce64ac35 100644 --- a/open-vm-tools/lib/misc/strutil.c +++ b/open-vm-tools/lib/misc/strutil.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2018 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -1341,7 +1341,6 @@ StrUtil_ReplaceAll(const char *orig, // IN char *tmp; size_t lenWhat; size_t lenWith; - size_t lenBefore; size_t occurrences = 0; size_t lenNew; @@ -1363,6 +1362,8 @@ StrUtil_ReplaceAll(const char *orig, // IN result = tmp; while (occurrences--) { + size_t lenBefore; + current = strstr(orig, what); lenBefore = current - orig; tmp = memcpy(tmp, orig, lenBefore); diff --git a/open-vm-tools/lib/misc/util_misc.c b/open-vm-tools/lib/misc/util_misc.c index e4b1bac4c..8fbedc62b 100644 --- a/open-vm-tools/lib/misc/util_misc.c +++ b/open-vm-tools/lib/misc/util_misc.c @@ -211,13 +211,14 @@ UtilGetLegacyEncodedString(const char *path) // IN: UTF-8 if (cpath != NULL) { char *apath = NULL; - int retlen; WCHAR *wcpath = Unicode_GetAllocUTF16(cpath); /* First get the length of multibyte string */ int alen = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wcpath, -1, NULL, 0, NULL, NULL); if (alen > 0) { + int retlen; + /* Now get the converted string */ ret = Util_SafeMalloc(alen); retlen = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wcpath, -1, diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c index e661993b3..6e1f4d8f9 100644 --- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c +++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c @@ -303,8 +303,6 @@ GuestInfoGetInterface(struct ifaddrs *ifaddrs, * records are intermingled with AF_INET and AF_INET6 records. */ for (pkt = ifaddrs; pkt != NULL; pkt = pkt->ifa_next) { - GuestNicV3 *nic; - struct ifaddrs *ip; struct sockaddr_ll *sll = (struct sockaddr_ll *)pkt->ifa_addr; if (GuestInfo_IfaceGetPriority(pkt->ifa_name) != priority || @@ -314,6 +312,8 @@ GuestInfoGetInterface(struct ifaddrs *ifaddrs, if (sll != NULL && sll->sll_family == AF_PACKET) { char macAddress[NICINFO_MAC_LEN]; + GuestNicV3 *nic; + struct ifaddrs *ip; /* * PR 2193804: @@ -672,8 +672,6 @@ ReadInterfaceDetails(const struct intf_entry *entry, // IN if (entry->intf_type == INTF_TYPE_ETH && entry->intf_link_addr.addr_type == ADDR_TYPE_ETH) { - GuestNicV3 *nic = NULL; - char macAddress[NICINFO_MAC_LEN]; /* * There is a race where the guest info plugin might be iterating over the @@ -683,6 +681,9 @@ ReadInterfaceDetails(const struct intf_entry *entry, // IN * pick up any changes. */ if (entry->intf_link_addr.addr_type == ADDR_TYPE_ETH) { + char macAddress[NICINFO_MAC_LEN]; + GuestNicV3 *nic = NULL; + Str_Sprintf(macAddress, sizeof macAddress, "%s", addr_ntoa(&entry->intf_link_addr)); diff --git a/open-vm-tools/lib/rpcChannel/simpleSocket.c b/open-vm-tools/lib/rpcChannel/simpleSocket.c index 463413730..9af19ea97 100644 --- a/open-vm-tools/lib/rpcChannel/simpleSocket.c +++ b/open-vm-tools/lib/rpcChannel/simpleSocket.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2013-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2013-2017,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -173,11 +173,10 @@ Socket_Recv(SOCKET fd, // IN int len) // IN { int remaining = len; - int rv; int sysErr; while (remaining > 0) { - rv = recv(fd, buf , remaining, 0); + int rv = recv(fd, buf , remaining, 0); if (rv == 0) { Debug(LGPFX "Socket %d closed by peer.", fd); return FALSE; diff --git a/open-vm-tools/lib/rpcIn/rpcin.c b/open-vm-tools/lib/rpcIn/rpcin.c index 47a3380e4..094cd228c 100644 --- a/open-vm-tools/lib/rpcIn/rpcin.c +++ b/open-vm-tools/lib/rpcIn/rpcin.c @@ -1071,7 +1071,6 @@ RpcInConnErrorHandler(int err, // IN void *clientData) // IN { ConnInfo *conn = (ConnInfo *)clientData; - char const *errmsg ="RpcIn: vsocket connection error"; RpcIn *in = conn->in; Debug("RpcIn: Error in socket %d, closing connection: %s.\n", @@ -1080,7 +1079,7 @@ RpcInConnErrorHandler(int err, // IN in->errStatus = TRUE; if (conn->connected) { - RpcInCloseChannel(conn->in, errmsg); + RpcInCloseChannel(conn->in, "RpcIn: vsocket connection error"); } else { /* the connection never gets connected */ RpcInCloseConn(conn); Debug("RpcIn: falling back to use backdoor ...\n"); diff --git a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c index eb157fba5..5ace167e2 100644 --- a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c +++ b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c @@ -2980,14 +2980,14 @@ void UnicodeICUTest(void) { StringEncoding enc, enc2; - const char *name; Bool supported; Bool redirected; Bool canGetBytes; for (enc = STRING_ENCODING_FIRST; enc < STRING_ENCODING_MAX_SPECIFIED; enc++ ) { - name = Unicode_EncodingEnumToName(enc); + const char *name = Unicode_EncodingEnumToName(enc); + enc2 = Unicode_EncodingNameToEnum(name); redirected = FALSE; if (enc2 == STRING_ENCODING_UNKNOWN) { diff --git a/open-vm-tools/lib/user/util.c b/open-vm-tools/lib/user/util.c index e89d13475..23376f452 100644 --- a/open-vm-tools/lib/user/util.c +++ b/open-vm-tools/lib/user/util.c @@ -205,13 +205,12 @@ Util_Checksumv(void *iov, // IN { uint32 checksum = 0; struct UtilVector *vector = (struct UtilVector *) iov; - uint32 partialChecksum; int bytesSoFar = 0; - int rotate; while (numEntries-- > 0) { - partialChecksum = Util_Checksum(vector->base, vector->len); - rotate = (bytesSoFar & 3) * 8; + uint32 partialChecksum = Util_Checksum(vector->base, vector->len); + int rotate = (bytesSoFar & 3) * 8; + checksum ^= ((partialChecksum << rotate) | (partialChecksum >> (32 - rotate))); bytesSoFar += vector->len; diff --git a/open-vm-tools/libDeployPkg/linuxDeployment.c b/open-vm-tools/libDeployPkg/linuxDeployment.c index 7615c9f8f..97a69cfd7 100644 --- a/open-vm-tools/libDeployPkg/linuxDeployment.c +++ b/open-vm-tools/libDeployPkg/linuxDeployment.c @@ -1219,7 +1219,6 @@ Deploy(const char* packageName) char* pkgCommand = NULL; char* command = NULL; int deploymentResult = 0; - char *nics; char* cleanupCommand; uint8 archiveType; uint8 flags; @@ -1348,7 +1347,8 @@ Deploy(const char* packageName) sLog(log_error, "Deployment failed." "The forked off process returned error code.\n"); } else { - nics = GetNicsToEnable(imcDirPath); + char *nics = GetNicsToEnable(imcDirPath); + if (nics) { // XXX: Sleep before the last SetCustomizationStatusInVmx // This is a temporary-hack for PR 422790 diff --git a/open-vm-tools/libDeployPkg/processPosix.c b/open-vm-tools/libDeployPkg/processPosix.c index b81ec80ed..340b05b01 100644 --- a/open-vm-tools/libDeployPkg/processPosix.c +++ b/open-vm-tools/libDeployPkg/processPosix.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2016,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -259,7 +259,6 @@ ProcessRead(ProcessInternal *p, ReadStatus *status, Bool stdout, Bool readToEof) { char buf[1024]; size_t currSize, newSize; - ssize_t count; char** saveTo; int fd; char* stdstr = stdout ? "stdout" : "stderr"; @@ -270,7 +269,8 @@ ProcessRead(ProcessInternal *p, ReadStatus *status, Bool stdout, Bool readToEof) // if there's output waiting, read it out. FDs should already be non-blocking do { - count = read(fd, buf, sizeof buf); + ssize_t count = read(fd, buf, sizeof buf); + if (count > 0) { // save output currSize = strlen(*saveTo); diff --git a/open-vm-tools/modules/solaris/vmxnet/vmxnet.c b/open-vm-tools/modules/solaris/vmxnet/vmxnet.c index 925985060..243c72575 100644 --- a/open-vm-tools/modules/solaris/vmxnet/vmxnet.c +++ b/open-vm-tools/modules/solaris/vmxnet/vmxnet.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2004 VMware, Inc. All rights reserved. + * Copyright (C) 2004,2019 VMware, Inc. All rights reserved. * * The contents of this file are subject to the terms of the Common * Development and Distribution License (the "License") version 1.0 @@ -405,9 +405,7 @@ Vxn_GetStats(gld_mac_info_t *macInfo, struct gld_stats *gs) static void Vxn_ApplyAddressFilter(vxn_softc_t *dp) { - uint8_t *ep; int i, j, bit, byte; - uint32_t crc, poly = CRC_POLYNOMIAL_LE; Vmxnet2_DriverData *dd = dp->driverData; volatile uint16_t *mcastTable = (uint16_t *)dd->LADRF; @@ -418,8 +416,9 @@ Vxn_ApplyAddressFilter(vxn_softc_t *dp) dd->LADRF[1] = 0; for (i = 0; i < dp->multiCount; i++) { - crc = 0xffffffff; - ep = (uint8_t *)&dp->multicastList[i].ether_addr_octet; + uint32_t crc = 0xffffffff; + uint32_t poly = CRC_POLYNOMIAL_LE; + uint8_t *ep = (uint8_t *)&dp->multicastList[i].ether_addr_octet; for (byte = 0; byte < 6; byte++) { for (bit = *ep++, j = 0; j < 8; j++, bit >>= 1) { @@ -1095,9 +1094,7 @@ Vxn_TxComplete(vxn_softc_t *dp, boolean_t *reschedp) static boolean_t Vxn_Receive(vxn_softc_t *dp) { - int ringnext; - short pktlen; - Vmxnet2_DriverData *dd = dp->driverData; + Vmxnet2_DriverData *dd = dp->driverData; rx_dma_buf_t *rxDesc; rx_dma_buf_t *newRxDesc; mblk_t *mblk; @@ -1109,17 +1106,18 @@ Vxn_Receive(vxn_softc_t *dp) ASSERT(MUTEX_HELD(&dp->intrlock)); /* - * Walk receive ring looking for entries with ownership + * Walk receive ring looking for entries with ownership * reverted back to driver */ while (1) { Vmxnet2_RxRingEntry *rre; rx_dma_buf_t **rbuf; + short pktlen; + int ringnext = dd->rxDriverNext; - ringnext = dd->rxDriverNext; rre = &dp->rxRing[ringnext]; rbuf = &dp->rxRingBuffPtr[ringnext]; - + if (rre->ownership != VMXNET2_OWNERSHIP_DRIVER) { break; } diff --git a/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_main.c b/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_main.c index a2b205e4f..28f2529f6 100644 --- a/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_main.c +++ b/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_main.c @@ -1200,7 +1200,6 @@ vmxnet3_get_prop(void *data, void *prop_val) { vmxnet3_softc_t *dp = data; - int ret = 0; switch (prop_id) { case MAC_PROP_MTU: { @@ -1210,7 +1209,6 @@ vmxnet3_get_prop(void *data, } default: { VMXNET3_WARN(dp, "vmxnet3_get_prop property %d not supported", prop_id); - ret = ENOTSUP; } } return (0); diff --git a/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_rx.c b/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_rx.c index f23a7914f..7866201bc 100644 --- a/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_rx.c +++ b/open-vm-tools/modules/solaris/vmxnet3/vmxnet3_rx.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007 VMware, Inc. All rights reserved. + * Copyright (C) 2007,2019 VMware, Inc. All rights reserved. * * The contents of this file are subject to the terms of the Common * Development and Distribution License (the "License") version 1.0 @@ -327,9 +327,9 @@ static void vmxnet3_rx_hwcksum(vmxnet3_softc_t *dp, mblk_t *mp, Vmxnet3_GenericDesc *compDesc) { - uint32_t flags = 0; - if (!compDesc->rcd.cnc) { + uint32_t flags = 0; + if (compDesc->rcd.v4 && compDesc->rcd.ipc) { flags |= HCK_IPV4_HDRCKSUM; if ((compDesc->rcd.tcp || compDesc->rcd.udp) && diff --git a/open-vm-tools/namespacetool/namespacetool.c b/open-vm-tools/namespacetool/namespacetool.c index c60976cfb..3e3319b8c 100644 --- a/open-vm-tools/namespacetool/namespacetool.c +++ b/open-vm-tools/namespacetool/namespacetool.c @@ -154,10 +154,11 @@ ValidateNSCommands(const gchar *cmdName) static void PrintInternalCommand(const char *data, size_t dataSize) { - int readCounter = 0; char *tmp = NULL; char *printBuf = NULL; if (dataSize > 0) { + int readCounter = 0; + printBuf = (char *) calloc((int)dataSize, sizeof(char)); if (printBuf == NULL) { fprintf(stderr, "Out of memory error"); @@ -527,8 +528,8 @@ static gboolean PostVerifySetKeyOptions(GOptionContext *context, GOptionGroup *group, gpointer data, GError **error) { - int usedOptions = 0; NamespaceOptionsState *nsOptions; + ASSERT(data); nsOptions = (NamespaceOptionsState *) data; @@ -543,6 +544,8 @@ PostVerifySetKeyOptions(GOptionContext *context, GOptionGroup *group, return FALSE; } if (g_strcmp0(nsOptions->cmdName, NSDB_SET_KEY_USER_CMD) == 0) { + int usedOptions = 0; + if (nsOptions->keyName == NULL) { g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Key name must be specified"); diff --git a/open-vm-tools/services/plugins/deployPkg/deployPkg.c b/open-vm-tools/services/plugins/deployPkg/deployPkg.c index 635a20164..8735cb6c4 100644 --- a/open-vm-tools/services/plugins/deployPkg/deployPkg.c +++ b/open-vm-tools/services/plugins/deployPkg/deployPkg.c @@ -175,12 +175,13 @@ ExitPoint: gboolean DeployPkg_TcloBegin(RpcInData *data) // IN { - static char resultBuffer[FILE_MAXPATH]; char *tempDir = DeployPkgGetTempDir(); g_debug("DeployPkgTcloBegin got call\n"); if (tempDir) { + static char resultBuffer[FILE_MAXPATH]; + Str_Strcpy(resultBuffer, tempDir, sizeof resultBuffer); free(tempDir); return RPCIN_SETRETVALS(data, resultBuffer, TRUE); @@ -210,7 +211,6 @@ DeployPkgExecDeploy(ToolsAppCtx *ctx, // IN: app context { char errMsg[2048]; ToolsDeployPkgError ret; - gchar *msg; char *pkgNameStr = (char *) pkgName; g_debug("%s: Deploypkg deploy task started.\n", __FUNCTION__); @@ -218,10 +218,11 @@ DeployPkgExecDeploy(ToolsAppCtx *ctx, // IN: app context /* Unpack the package and run the command. */ ret = DeployPkgDeployPkgInGuest(ctx, pkgNameStr, errMsg, sizeof errMsg); if (ret != TOOLSDEPLOYPKG_ERROR_SUCCESS) { - msg = g_strdup_printf("deployPkg.update.state %d %d %s", - TOOLSDEPLOYPKG_DEPLOYING, - TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED, - errMsg); + gchar *msg = g_strdup_printf("deployPkg.update.state %d %d %s", + TOOLSDEPLOYPKG_DEPLOYING, + TOOLSDEPLOYPKG_ERROR_DEPLOY_FAILED, + errMsg); + if (!RpcChannel_Send(ctx->rpc, msg, strlen(msg), NULL, NULL)) { g_warning("%s: failed to send error code %d for state TOOLSDEPLOYPKG_DEPLOYING\n", __FUNCTION__, diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c b/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c index e8eca5176..248073405 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c +++ b/open-vm-tools/services/plugins/dndcp/copyPasteCompatX11.c @@ -156,7 +156,6 @@ CopyPasteSelectionRemoveTarget(GtkWidget *widget, GdkAtom target) { const char *selection_handler_key = "gtk-selection-handlers"; - struct SelectionTargetList *targetList; GList *tempList; GList *selectionLists; @@ -169,7 +168,7 @@ CopyPasteSelectionRemoveTarget(GtkWidget *widget, tempList = selectionLists; while (tempList) { /* Enumerate the list to find the selection. */ - targetList = tempList->data; + struct SelectionTargetList *targetList = tempList->data; if (targetList->selection == selection) { /* Remove target. */ gtk_target_list_remove(targetList->list, target); @@ -681,11 +680,8 @@ void CopyPasteSetBackdoorSelections(void) { uint32 const *p; - size_t len; - size_t aligned_len; size_t primaryLen; size_t clipboardLen; - unsigned int i; primaryLen = strlen(gGuestSelPrimaryBuf); clipboardLen = strlen(gGuestSelClipboardBuf); @@ -716,7 +712,10 @@ CopyPasteSetBackdoorSelections(void) CopyPaste_SetSelLength(0); g_debug("CopyPasteSetBackdoorSelections Set empty text.\n"); } else { - len = strlen((char *)p); + size_t len = strlen((char *)p); + size_t aligned_len; + unsigned int i; + g_debug("CopyPasteSetBackdoorSelections Set text [%s].\n", (char *)p); aligned_len = (len + 4) & ~3; diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp b/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp index fad000e3a..89e5f661e 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp +++ b/open-vm-tools/services/plugins/dndcp/copyPasteUIX11.cpp @@ -990,7 +990,6 @@ CopyPasteUIX11::LocalGetSelectionFileList(const Gtk::SelectionData& sd) // { utf::string source; char *newPath; - char *newRelPath; size_t newPathLen; size_t index = 0; DnDFileList fileList; @@ -1025,6 +1024,8 @@ CopyPasteUIX11::LocalGetSelectionFileList(const Gtk::SelectionData& sd) // while ((newPath = DnD_UriListGetNextFile(source.c_str(), &index, &newPathLen)) != NULL) { + char *newRelPath; + #if defined(__linux__) if (DnD_UriIsNonFileSchemes(newPath)) { /* Try to get local file path for non file uri. */ diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndMsg.c b/open-vm-tools/services/plugins/dndcp/dnd/dndMsg.c index eb1f81bdb..291d5db7c 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndMsg.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndMsg.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2016,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -288,7 +288,6 @@ Bool DnDMsg_Serialize(DnDMsg *msg, // IN/OUT: the message DynBuf* buf) // OUT: the output buffer { - DynBuf *curArg; uint32 nargs; uint32 i; uint32 serializeArgsSz = 0; @@ -313,7 +312,8 @@ DnDMsg_Serialize(DnDMsg *msg, // IN/OUT: the message uint32 curArgsSz; for (i = 0; i < nargs; i++) { - curArg = DynBufArray_AddressOf(&msg->args, i); + DynBuf *curArg = DynBufArray_AddressOf(&msg->args, i); + curArgsSz = DynBuf_GetSize(curArg); if (!DynBuf_Append(buf, &curArgsSz, sizeof curArgsSz) || diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c b/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c index cf837002a..da54ee585 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndXdg.c @@ -85,10 +85,11 @@ const char * Xdg_GetCacheHome(void) { static char *result = NULL; - struct passwd *pw; if (result == NULL) { do { + struct passwd *pw; + if (!Id_IsSetUGid()) { const char *base = NULL; diff --git a/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp b/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp index 015dd3631..8eb7f826c 100644 --- a/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp +++ b/open-vm-tools/services/plugins/dndcp/dndUIX11.cpp @@ -1079,7 +1079,6 @@ DnDUIX11::OnGtkDragDataGet( guint info, // UNUSED guint time) // IN: event timestamp { - size_t index = 0; std::string str; std::string uriList; std::string stagingDirName; @@ -1105,6 +1104,7 @@ DnDUIX11::OnGtkDragDataGet( if ( target == DRAG_TARGET_NAME_URI_LIST && CPClipboard_GetItem(&mClipboard, CPFORMAT_FILELIST, &buf, &sz)) { + size_t index = 0; /* Provide path within vmblock file system instead of actual path. */ stagingDirName = GetLastDirName(mHGStagingDir); @@ -1413,10 +1413,6 @@ DnDUIX11::OnGtkDragDrop( bool DnDUIX11::SetCPClipboardFromGtk(const Gtk::SelectionData& sd) // IN { - char *newPath; - char *newRelPath; - size_t newPathLen; - size_t index = 0; DnDFileList fileList; DynBuf buf; uint64 totalSize = 0; @@ -1431,6 +1427,10 @@ DnDUIX11::SetCPClipboardFromGtk(const Gtk::SelectionData& sd) // IN * one for just the last path component. */ utf::string source = sd.get_data_as_string().c_str(); + size_t index = 0; + char *newPath; + size_t newPathLen; + g_debug("%s: Got file list: [%s]\n", __FUNCTION__, source.c_str()); if (sd.get_data_as_string().length() == 0) { @@ -1458,6 +1458,8 @@ DnDUIX11::SetCPClipboardFromGtk(const Gtk::SelectionData& sd) // IN while ((newPath = DnD_UriListGetNextFile(source.c_str(), &index, &newPathLen)) != NULL) { + char *newRelPath; + #if defined(__linux__) if (DnD_UriIsNonFileSchemes(newPath)) { /* Try to get local file path for non file uri. */ diff --git a/open-vm-tools/services/plugins/dndcp/pointer.cpp b/open-vm-tools/services/plugins/dndcp/pointer.cpp index b5ae29747..b4cfcc4b9 100644 --- a/open-vm-tools/services/plugins/dndcp/pointer.cpp +++ b/open-vm-tools/services/plugins/dndcp/pointer.cpp @@ -393,13 +393,12 @@ PointerUpdatePointerLoop(gpointer clientData) // IN: unused if (!CopyPaste_IsRpcCPSupported() || (absoluteMouseState == ABSMOUSE_UNAVAILABLE)) { - - GSource *src; - CopyPasteDnDWrapper *wrapper = CopyPasteDnDWrapper::GetInstance(); ToolsAppCtx *ctx = wrapper->GetToolsAppCtx(); + if (ctx) { - src = VMTools_CreateTimer(POINTER_UPDATE_TIMEOUT); + GSource *src = VMTools_CreateTimer(POINTER_UPDATE_TIMEOUT); + VMTOOLSAPP_ATTACH_SOURCE(ctx, src, PointerUpdatePointerLoop, NULL, NULL); g_source_unref(src); } diff --git a/open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.cpp b/open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.cpp index b7cbb0e4e..86060b53f 100644 --- a/open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.cpp +++ b/open-vm-tools/services/plugins/dndcp/vmCopyPasteDnDWrapper.cpp @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2018 VMware, Inc. All rights reserved. + * Copyright (C) 2018-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -138,15 +138,18 @@ VMCopyPasteDnDWrapper::RemoveDnDPluginResetTimer(void) void VMCopyPasteDnDWrapper::OnCapReg(gboolean set) { + ToolsAppCtx *ctx; + g_debug("%s: enter\n", __FUNCTION__); - char *reply = NULL; - size_t replyLen; - const char *toolsDnDVersion = TOOLS_DND_VERSION_4; - char *toolsCopyPasteVersion = NULL; - int version; - ToolsAppCtx *ctx = GetToolsAppCtx(); + ctx = GetToolsAppCtx(); if (ctx) { + char *reply = NULL; + size_t replyLen; + const char *toolsDnDVersion = TOOLS_DND_VERSION_4; + char *toolsCopyPasteVersion = NULL; + int version; + /* * First DnD. */ diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c index b5f766c8f..5c343e66c 100644 --- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c +++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c @@ -1796,9 +1796,7 @@ static Bool DiskInfoChanged(const GuestDiskInfoInt *diskInfo) { int index; - char *name; int i; - int matchedPartition; GuestDiskInfoInt *cachedDiskInfo; cachedDiskInfo = gInfoCache.diskInfo; @@ -1817,7 +1815,8 @@ DiskInfoChanged(const GuestDiskInfoInt *diskInfo) /* Have any disks been modified? */ for (index = 0; index < cachedDiskInfo->numEntries; index++) { - name = cachedDiskInfo->partitionList[index].name; + int matchedPartition; + char *name = cachedDiskInfo->partitionList[index].name; /* Find the corresponding partition in the new partition info. */ for (i = 0; i < diskInfo->numEntries; i++) { diff --git a/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c b/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c index 7be698458..6340b113b 100644 --- a/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c +++ b/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2010-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2010-2017,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -827,8 +827,6 @@ RandR12DeleteModes(Display *display, // IN: The display connection RandR12Info *info) // IN: RandR12Info context { XRRScreenResources *xrrRes = info->xrrRes; - XRRModeInfo *modeInfo; - RandR12Output *rrOutput; unsigned int i, j; unsigned int w, h; Bool used; @@ -839,7 +837,8 @@ RandR12DeleteModes(Display *display, // IN: The display connection */ for (i = 0; i < xrrRes->nmode; ++i) { - modeInfo = &xrrRes->modes[i]; + XRRModeInfo *modeInfo = &xrrRes->modes[i]; + if (sscanf(modeInfo->name, RR12_MODE_FORMAT, &w, &h) != 2) { continue; } @@ -854,7 +853,7 @@ RandR12DeleteModes(Display *display, // IN: The display connection */ for (j = 0; j < info->nOutput; ++j) { - rrOutput = &info->outputs[j]; + RandR12Output *rrOutput = &info->outputs[j]; if (rrOutput->mode != modeInfo->id) { if (RandR12OutputHasMode(rrOutput->output, modeInfo)) { diff --git a/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c b/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c index e17a58a28..c5591139d 100644 --- a/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c +++ b/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2017 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2017,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -17,7 +17,7 @@ *********************************************************/ /* - * @file resolutionX11.c + * @file resolutionX11.c * * X11 backend for resolutionSet plugin. */ @@ -375,16 +375,18 @@ ResolutionCanSet(void) */ if (major > 1 || (major == 1 && minor >= 2)) { XRRScreenResources* xrrRes; - XRROutputInfo* xrrOutput; unsigned int num; - int i; xrrRes = XRRGetScreenResources(resInfoX->display, resInfoX->rootWindow); if (xrrRes) { + int i; + for (i = 0; i < xrrRes->noutput; i++) { - xrrOutput = XRRGetOutputInfo(resInfoX->display, xrrRes, - xrrRes->outputs[i]); + XRROutputInfo* xrrOutput = + XRRGetOutputInfo(resInfoX->display, xrrRes, + xrrRes->outputs[i]); + if (!xrrOutput) { break; } diff --git a/open-vm-tools/services/plugins/vmbackup/scriptOps.c b/open-vm-tools/services/plugins/vmbackup/scriptOps.c index 0f24ffa57..f8ce30f7d 100644 --- a/open-vm-tools/services/plugins/vmbackup/scriptOps.c +++ b/open-vm-tools/services/plugins/vmbackup/scriptOps.c @@ -154,9 +154,9 @@ VmBackupRunNextScript(VmBackupScriptOp *op) // IN/OUT } while (index >= 0 && scripts[index].path != NULL) { - char *cmd; - if (File_IsFile(scripts[index].path)) { + char *cmd; + if (op->state->scriptArg != NULL) { cmd = Str_Asprintf(NULL, "\"%s\" %s \"%s\"", scripts[index].path, scriptOp, op->state->scriptArg); @@ -345,11 +345,12 @@ exit: static void VmBackupScriptOpRelease(VmBackupOp *_op) // IN { - size_t i; VmBackupScriptOp *op = (VmBackupScriptOp *) _op; if (op->type != VMBACKUP_SCRIPT_FREEZE && op->state->scripts != NULL) { + size_t i; VmBackupScript *scripts = op->state->scripts; + for (i = 0; scripts[i].path != NULL; i++) { free(scripts[i].path); if (scripts[i].proc != NULL) { diff --git a/open-vm-tools/services/vmtoolsd/toolsRpc.c b/open-vm-tools/services/vmtoolsd/toolsRpc.c index e9e3ef7f9..53133731c 100644 --- a/open-vm-tools/services/vmtoolsd/toolsRpc.c +++ b/open-vm-tools/services/vmtoolsd/toolsRpc.c @@ -354,7 +354,6 @@ ToolsCore_InitRpc(ToolsServiceState *state) { "Set_Option", ToolsCoreRpcSetOption, NULL, NULL, NULL, 0 }, }; - size_t i; const gchar *app; GMainContext *mainCtx = g_main_loop_get_context(state->ctx.mainLoop); @@ -396,6 +395,7 @@ ToolsCore_InitRpc(ToolsServiceState *state) */ RpcChannelFailureCb failureCb = NULL; guint errorLimit = 0; + size_t i; #if !defined(_WIN32) diff --git a/open-vm-tools/tests/testVmblock/manual-blocker.c b/open-vm-tools/tests/testVmblock/manual-blocker.c index 42ac297db..012926bf5 100644 --- a/open-vm-tools/tests/testVmblock/manual-blocker.c +++ b/open-vm-tools/tests/testVmblock/manual-blocker.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2016,2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -55,7 +55,6 @@ main(int argc, char *argv[]) { int status; - char op; if (argc < 2 || strcmp(argv[1], "-h") == 0 || @@ -74,7 +73,8 @@ main(int argc, printf("Opened " VMBLOCK_DEVICE " as fd %d.\n", fd); while (1) { - op = getchar(); + char op = getchar(); + if (op == 'a') { status = VMBLOCK_CONTROL(fd, VMBLOCK_ADD_FILEBLOCK, argv[1]); if (status != 0) { diff --git a/open-vm-tools/vgauth/service/fileLogger.c b/open-vm-tools/vgauth/service/fileLogger.c index 06ae1c3f5..eca231d89 100644 --- a/open-vm-tools/vgauth/service/fileLogger.c +++ b/open-vm-tools/vgauth/service/fileLogger.c @@ -87,7 +87,6 @@ ServiceFileLoggerOpen(FileLoggerData *data) * will always be index "0"). When not rotating, "maxFiles" is 1, so we * always keep one backup. */ - gchar *fname; guint id; GPtrArray *logfiles = g_ptr_array_new(); @@ -97,7 +96,8 @@ ServiceFileLoggerOpen(FileLoggerData *data) * file, which may or may not exist. */ for (id = 0; id < data->maxFiles; id++) { - fname = g_strdup_printf("%s.%d", data->path, id); + gchar *fname = g_strdup_printf("%s.%d", data->path, id); + g_ptr_array_add(logfiles, fname); if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR)) { break; diff --git a/open-vm-tools/vgauth/service/gio.c b/open-vm-tools/vgauth/service/gio.c index 1ff6a2943..ce2e2ac17 100644 --- a/open-vm-tools/vgauth/service/gio.c +++ b/open-vm-tools/vgauth/service/gio.c @@ -338,12 +338,7 @@ ServiceIOAcceptGSource(gpointer userData) { ServiceConnection *newConn = NULL; ServiceConnection *lConn = (ServiceConnection *) userData; - VGAuthError err = VGAUTH_E_OK; -#ifdef _WIN32 - GSource *gSourceData; -#else - GIOChannel *echan; -#endif + VGAuthError err; err = ServiceConnectionClone(lConn, &newConn); if (VGAUTH_E_OK != err) { @@ -353,6 +348,12 @@ ServiceIOAcceptGSource(gpointer userData) err = ServiceAcceptConnection(lConn, newConn); if (VGAUTH_E_OK == err) { +#ifdef _WIN32 + GSource *gSourceData; +#else + GIOChannel *echan; +#endif + VGAUTH_LOG_DEBUG("Established a new pipe connection %d on %s", newConn->connId, newConn->pipeName); #ifdef _WIN32 diff --git a/open-vm-tools/vgauth/serviceImpl/alias.c b/open-vm-tools/vgauth/serviceImpl/alias.c index 0ee824469..89156008b 100644 --- a/open-vm-tools/vgauth/serviceImpl/alias.c +++ b/open-vm-tools/vgauth/serviceImpl/alias.c @@ -1087,7 +1087,6 @@ AliasStartElement(GMarkupParseContext *parseContext, { AliasParseList *list = (AliasParseList *) userData; ServiceAliasInfo *infos; - int n; ASSERT(list); @@ -1132,6 +1131,8 @@ AliasStartElement(GMarkupParseContext *parseContext, break; case ALIAS_PARSE_STATE_ALIASINFOS: if (g_strcmp0(elementName, ALIASINFO_ALIASINFO_ELEMENT_NAME) == 0) { + int n; + list->state = ALIAS_PARSE_STATE_ALIASINFO; // grow diff --git a/open-vm-tools/vgauth/serviceImpl/proto.c b/open-vm-tools/vgauth/serviceImpl/proto.c index 3cef3b55d..dc1dfd7f2 100644 --- a/open-vm-tools/vgauth/serviceImpl/proto.c +++ b/open-vm-tools/vgauth/serviceImpl/proto.c @@ -1833,10 +1833,7 @@ ServiceProtoQueryMappedAliases(ServiceConnection *conn, { VGAuthError err; gchar *packet; - gchar *endPacket; int num; - int i; - int j; ServiceMappedAlias *maList; /* @@ -1848,10 +1845,14 @@ ServiceProtoQueryMappedAliases(ServiceConnection *conn, if (err != VGAUTH_E_OK) { packet = Proto_MakeErrorReply(conn, req, err, "queryMappedIds failed"); } else { + int i; + gchar *endPacket; + packet = g_markup_printf_escaped(VGAUTH_QUERYMAPPEDALIASES_REPLY_FORMAT_START, req->sequenceNumber); for (i = 0; i < num; i++) { gchar *tPacket; + int j; tPacket = g_markup_printf_escaped(VGAUTH_MAPPEDALIASES_FORMAT_START, maList[i].userName, diff --git a/open-vm-tools/vgauth/serviceImpl/verify.c b/open-vm-tools/vgauth/serviceImpl/verify.c index bda1013ea..1a47c6c1b 100644 --- a/open-vm-tools/vgauth/serviceImpl/verify.c +++ b/open-vm-tools/vgauth/serviceImpl/verify.c @@ -118,10 +118,8 @@ ServiceVerifyAndCheckTrustCertChainForSubject(int numCerts, * Dump the token cert chain for debugging purposes. */ if (gVerboseLogging) { - gchar *chainx509; - for (i = 0; i < numCerts; i++) { - chainx509 = CertVerify_CertToX509String(pemCertChain[i]); + gchar *chainx509 = CertVerify_CertToX509String(pemCertChain[i]); Debug("%s: Token chain cert #%d:\n%s", __FUNCTION__, i, chainx509); g_free(chainx509); } @@ -225,12 +223,11 @@ ServiceVerifyAndCheckTrustCertChainForSubject(int numCerts, * Dump the store cert chain for debugging purposes. */ if (gVerboseLogging) { - gchar *storex509; - Debug("%s: %d certs in store for user %s\n", __FUNCTION__, numStoreCerts, queryUserName); for (i = 0; i < numStoreCerts; i++) { - storex509 = CertVerify_CertToX509String(aList[i].pemCert); + gchar *storex509 = CertVerify_CertToX509String(aList[i].pemCert); + Debug("%s: Store chain cert #%d:\n%s", __FUNCTION__, i, storex509); g_free(storex509); } diff --git a/open-vm-tools/vmblock-fuse/fsops.c b/open-vm-tools/vmblock-fuse/fsops.c index 2817d90f9..28337d80b 100644 --- a/open-vm-tools/vmblock-fuse/fsops.c +++ b/open-vm-tools/vmblock-fuse/fsops.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2018 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -252,7 +252,6 @@ int VMBlockGetAttr(const char *path, // IN: File to get attributes of. struct stat *statBuf) // OUT: Where to put the attributes. { - int status; char target[PATH_MAX + 1]; vmblockSpecialDirEntry *dirEntry; ASSERT(path != NULL); @@ -273,7 +272,8 @@ VMBlockGetAttr(const char *path, // IN: File to get attributes of. } } if (strncmp(path, REDIRECT_DIR, strlen(REDIRECT_DIR)) == 0) { - status = RealReadLink(path, target, sizeof target); + int status = RealReadLink(path, target, sizeof target); + LOG(4, "%s: Called RealReadLink which returned: %d\n", __func__, status); if (status != 0) { return status; @@ -675,8 +675,6 @@ VMBlockRead(const char *path, // IN: Must be control file. off_t offset, // IN: Ignored. struct fuse_file_info *fileInfo) // IN: Ignored. { - char target[PATH_MAX+1]; - char targetLink[PATH_MAX+1]; const char redirectPrefix[] = REDIRECT_DIR "/"; const char redirectPrefixLength = sizeof redirectPrefix - 1; const char notifyPrefix[] = NOTIFY_DIR "/"; @@ -696,6 +694,9 @@ VMBlockRead(const char *path, // IN: Must be control file. } if (strncmp(path, NOTIFY_DIR, strlen(NOTIFY_DIR)) == 0) { + char target[PATH_MAX+1]; + char targetLink[PATH_MAX+1]; + strlcpy(target, redirectPrefix, sizeof target); strlcpy(target + redirectPrefixLength, relativePath, diff --git a/open-vm-tools/vmhgfs-fuse/cache.c b/open-vm-tools/vmhgfs-fuse/cache.c index 5c56ce3cb..c3167cac2 100644 --- a/open-vm-tools/vmhgfs-fuse/cache.c +++ b/open-vm-tools/vmhgfs-fuse/cache.c @@ -322,12 +322,13 @@ HgfsGetAttrCache(const char* path, //IN: Path of file or directory { HgfsAttrCache *tmp; int res = -1; - int diff; pthread_mutex_lock(&HgfsAttrCacheLock); tmp = (HgfsAttrCache *)g_hash_table_lookup(g_hash_table, path); if (tmp != NULL) { + int diff; + LOG(4, ("cache hit. path = %s\n", tmp->path)); diff = (HGFS_GET_TIME(time(NULL)) - tmp->changeTime) / 10000000; diff --git a/open-vm-tools/vmhgfs-fuse/file.c b/open-vm-tools/vmhgfs-fuse/file.c index 14b68960d..e56d621db 100644 --- a/open-vm-tools/vmhgfs-fuse/file.c +++ b/open-vm-tools/vmhgfs-fuse/file.c @@ -1161,8 +1161,6 @@ HgfsPackSetattrRequest(const char *path, // IN: path to file HgfsReq *req) // IN/OUT: req packet { HgfsAttrV2 *attrV2; - HgfsAttr *attrV1; - HgfsAttrChanges *update; size_t reqBufferSize; size_t reqSize; ASSERT(req); @@ -1297,10 +1295,11 @@ HgfsPackSetattrRequest(const char *path, // IN: path to file } case HGFS_OP_SETATTR: { int result; + HgfsAttr *attrV1; HgfsRequestSetattr *request; + HgfsAttrChanges *update; request = (HgfsRequestSetattr *)(HGFS_REQ_PAYLOAD(req)); - attrV1 = &request->attr; update = &request->update; -- 2.47.3