Skip to content

Commit

Permalink
Address issues reported by Coverity.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwvmw committed Aug 21, 2022
1 parent d2b1bb8 commit a4f13c6
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
7 changes: 5 additions & 2 deletions open-vm-tools/lib/appUtil/appUtilX11.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2008-2019 VMware, Inc. All rights reserved.
* Copyright (C) 2008-2019,2022 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
Expand Down Expand Up @@ -174,6 +174,9 @@ AppUtilCollectNamedIcons(GPtrArray *pixbufs, // IN/OUT
*/
iconSearchNameSize = strlen(iconName) + 1;
iconSearchName = g_alloca(iconSearchNameSize);

/* Ignore return, returns length of the source string */
/* coverity[check_return] */
g_strlcpy(iconSearchName, iconName, iconSearchNameSize);

myIconName = NULL;
Expand Down Expand Up @@ -769,7 +772,7 @@ AppUtil_AppIsSkippable(const char *appName)
* Path, or NULL if not available
*
* Side effects:
* Allocated memory is returned
* Allocated memory is returned
*
*-----------------------------------------------------------------------------
*/
Expand Down
3 changes: 3 additions & 0 deletions open-vm-tools/lib/globalConfig/globalConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ LoadConfigFile(const gchar *confPath,
}

cfg = g_key_file_new();

/* On error, 'err' will be set, null otherwise. */
/* coverity[check_return] */
g_key_file_load_from_file(cfg, confPath,
G_KEY_FILE_NONE, &err);
if (err != NULL) {
Expand Down
13 changes: 10 additions & 3 deletions open-vm-tools/lib/hgfs/cpName.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 1998-2016 VMware, Inc. All rights reserved.
* Copyright (C) 1998-2016,2022 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
Expand Down Expand Up @@ -168,7 +168,14 @@ CPNameEscapeAndConvertFrom(char const **bufIn, // IN/OUT: Input to convert
}

/* Leaving space for the leading path separator, thus output to savedBufOut + 1. */
*inSize = HgfsEscape_Do(*bufIn, *inSize, savedOutSize, savedBufOut + 1);
result = HgfsEscape_Do(*bufIn, *inSize, savedOutSize - 1, savedBufOut + 1);
if (result < 0) {
Log("%s: error: not enough room to perform escape: %d\n",
__FUNCTION__, result);
return -1;
}
*inSize = (size_t) result;

result = CPNameConvertFrom(&savedOutConst, inSize, outSize, bufOut, pathSep);
*bufIn += *inSize;
*inSize = 0;
Expand Down Expand Up @@ -221,10 +228,10 @@ CPNameConvertFrom(char const **bufIn, // IN/OUT: Input to convert
ASSERT(bufOut);

in = *bufIn;
inEnd = in + *inSize;
if (inPlaceConvertion) {
in++; // Skip place for the leading path separator.
}
inEnd = in + *inSize;
myOutSize = *outSize;
out = *bufOut;

Expand Down
3 changes: 1 addition & 2 deletions open-vm-tools/lib/hgfs/hgfsEscape.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2008-2019 VMware, Inc. All rights reserved.
* Copyright (C) 2008-2019,2022 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
Expand Down Expand Up @@ -842,7 +842,6 @@ HgfsEscape_Undo(char *bufIn, // IN: Characters to be unescaped
result += componentSize;
if (unprocessedSize > 1) {
currentComponent = currentComponent + componentSize;
componentSize = strlen(currentComponent) + 1; // Size of the next component
} else {
currentComponent = NULL;
}
Expand Down
4 changes: 3 additions & 1 deletion open-vm-tools/libvmtools/vmtoolsConfig.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2008-2021 VMware, Inc. All rights reserved.
* Copyright (C) 2008-2022 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
Expand Down Expand Up @@ -150,6 +150,8 @@ VMTools_LoadConfig(const gchar *path,
goto exit;
}

/* On error, 'err' will be set, null otherwise */
/* coverity[check_return] */
g_key_file_load_from_file(cfg, localPath, flags, &err);
if (err == NULL || err->code == G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
goto exit;
Expand Down
4 changes: 2 additions & 2 deletions open-vm-tools/namespacetool/namespacetool.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2016-2020 VMware, Inc. All rights reserved.
* Copyright (C) 2016-2020,2022 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
Expand Down Expand Up @@ -279,7 +279,7 @@ GetValueFromFile(const char *filePath, char **fileContents, gsize *length)
*fileContents = NULL;
*length = 0;
}
g_free(gErr);
g_error_free(gErr);
return retVal;
}

Expand Down
2 changes: 2 additions & 0 deletions open-vm-tools/vgauth/common/certverify.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ VerifyCallback(int ok,
X509_NAME_oneline(X509_get_subject_name(curCert), nameBuf, sizeof(nameBuf) - 1);
nameBuf[sizeof(nameBuf)-1] = '\0';
} else {
/* Ignore return, returns length of the source string */
/* coverity[check_return] */
g_strlcpy(nameBuf, "<NO CERT SUBJECT>", sizeof nameBuf);
}
g_debug("%s: name: %s ok: %d error '%s' (%d) at %d depth lookup:%s\n",
Expand Down
4 changes: 3 additions & 1 deletion open-vm-tools/vgauth/lib/netPosix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2011-2016,2019 VMware, Inc. All rights reserved.
* Copyright (C) 2011-2016,2019,2022 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
Expand Down Expand Up @@ -74,6 +74,8 @@ VGAuth_NetworkConnect(VGAuthContext *ctx)
return VGAUTH_E_COMM;
}

/* Ignore return, returns the length of the source string */
/* coverity[check_return] */
g_strlcpy(sockaddr.sun_path, ctx->comm.pipeName, UNIX_PATH_MAX);

do {
Expand Down
11 changes: 9 additions & 2 deletions open-vm-tools/vgauth/serviceImpl/netPosix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 2011-2017, 2019-2021 VMware, Inc. All rights reserved.
* Copyright (C) 2011-2017, 2019-2022 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
Expand Down Expand Up @@ -151,8 +151,14 @@ ServiceNetworkListen(ServiceConnection *conn, // IN/OUT

sockaddr.sun_family = PF_UNIX;

g_unlink(conn->pipeName);
ret = g_unlink(conn->pipeName);
if (ret < 0 && errno != ENOENT) {
Warning("%s: unlink(%s) failed, %d - continuing\n", __FUNCTION__,
conn->pipeName, errno);
}

/* Ignore return, returns the length of the source string */
/* coverity[check_return] */
g_strlcpy(sockaddr.sun_path, conn->pipeName, UNIX_PATH_MAX);

ret = bind(sock, (struct sockaddr *) &sockaddr, sizeof sockaddr);
Expand Down Expand Up @@ -304,6 +310,7 @@ ServiceNetworkCloseConnection(ServiceConnection *conn)
void
ServiceNetworkRemoveListenPipe(ServiceConnection *conn)
{
/* coverity[check_return] */
ServiceFileUnlinkFile(conn->pipeName);
}

Expand Down

0 comments on commit a4f13c6

Please sign in to comment.