[X2Go-Commits] [nx-libs] 16/29: Error.c: replace strcpy/strcat by snprintf
git-admin at x2go.org
git-admin at x2go.org
Sun Jan 7 01:30:59 CET 2018
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch 3.6.x
in repository nx-libs.
commit 525e151681ec93657f027645ff0d8e0d487d6abf
Author: Ulrich Sibiller <uli42 at gmx.de>
Date: Wed Jan 3 00:06:39 2018 +0100
Error.c: replace strcpy/strcat by snprintf
---
nx-X11/programs/Xserver/hw/nxagent/Display.c | 3 +--
nx-X11/programs/Xserver/hw/nxagent/Error.c | 31 +++++++++++-----------------
2 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c
index b78530e..31efab8 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Display.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c
@@ -1873,8 +1873,7 @@ static FILE *nxagentLookForIconFile(char *iconName, const char *permission,
/* append slash and icon name */
if (strlen(singlePath) + strlen(iconName) + 1 < sizeof(singlePath))
{
- strncat(singlePath, slash, 1);
- strcat(singlePath, iconName);
+ snprintf(singlePath + strlen(singlePath), sizeof(singlePath), "%s%s", slash, iconName);
if ((fptr = fopen(singlePath, permission)) != NULL)
{
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Error.c b/nx-X11/programs/Xserver/hw/nxagent/Error.c
index 4a80ec5..7420a8b 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Error.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Error.c
@@ -359,14 +359,14 @@ char *nxagentGetHomePath(void)
#endif
}
- strncpy(nxagentHomeDir, homeEnv, DEFAULT_STRING_LENGTH - 1);
+ snprintf(nxagentHomeDir, DEFAULT_STRING_LENGTH, "%s", homeEnv);
#ifdef TEST
fprintf(stderr, "nxagentGetHomePath: Assuming NX user's home directory '%s'.\n", nxagentHomeDir);
#endif
}
- homePath = (char*) malloc(strlen(nxagentHomeDir) + 1);
+ homePath = strdup(nxagentHomeDir);
if (homePath == NULL)
{
@@ -377,8 +377,6 @@ char *nxagentGetHomePath(void)
return NULL;
}
- strcpy(homePath, nxagentHomeDir);
-
return homePath;
}
@@ -434,8 +432,7 @@ char *nxagentGetRootPath(void)
fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory in '%s'.\n", homeEnv);
#endif
- strcpy(nxagentRootDir, homeEnv);
- strcat(nxagentRootDir, "/.nx");
+ snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s/.nx", homeEnv);
free(homeEnv);
@@ -468,17 +465,17 @@ char *nxagentGetRootPath(void)
return NULL;
}
- strcpy(nxagentRootDir, rootEnv);
+ snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s", rootEnv);
}
#ifdef TEST
fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory '%s'.\n",
nxagentRootDir);
#endif
-
+
}
- rootPath = malloc(strlen(nxagentRootDir) + 1);
+ rootPath = strdup(nxagentRootDir);
if (rootPath == NULL)
{
@@ -489,8 +486,6 @@ char *nxagentGetRootPath(void)
return NULL;
}
- strcpy(rootPath, nxagentRootDir);
-
return rootPath;
}
@@ -527,9 +522,7 @@ char *nxagentGetSessionPath(void)
return NULL;
}
- strcpy(nxagentSessionDir, rootPath);
-
- free(rootPath);
+ snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s", rootPath);
if (strlen(nxagentSessionDir) + strlen("/C-") + strlen(nxagentSessionId) > DEFAULT_STRING_LENGTH - 1)
{
@@ -538,12 +531,14 @@ char *nxagentGetSessionPath(void)
nxagentSessionDir);
#endif
+ free(rootPath);
+
return NULL;
}
- strcat(nxagentSessionDir, "/C-");
+ snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s/C-%s", rootPath, nxagentSessionId);
- strcat(nxagentSessionDir, nxagentSessionId);
+ free(rootPath);
if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT))
{
@@ -605,9 +600,7 @@ void nxagentGetClientsPath()
return;
}
- strcpy(nxagentClientsLogName, sessionPath);
-
- strcat(nxagentClientsLogName, "/clients");
+ snprintf(nxagentClientsLogName, DEFAULT_STRING_LENGTH, "%s/clients", sessionPath);
free(sessionPath);
}
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git
More information about the x2go-commits
mailing list