Commit 525e1516 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Error.c: replace strcpy/strcat by snprintf

parent 7d87e5a0
...@@ -1873,8 +1873,7 @@ static FILE *nxagentLookForIconFile(char *iconName, const char *permission, ...@@ -1873,8 +1873,7 @@ static FILE *nxagentLookForIconFile(char *iconName, const char *permission,
/* append slash and icon name */ /* append slash and icon name */
if (strlen(singlePath) + strlen(iconName) + 1 < sizeof(singlePath)) if (strlen(singlePath) + strlen(iconName) + 1 < sizeof(singlePath))
{ {
strncat(singlePath, slash, 1); snprintf(singlePath + strlen(singlePath), sizeof(singlePath), "%s%s", slash, iconName);
strcat(singlePath, iconName);
if ((fptr = fopen(singlePath, permission)) != NULL) if ((fptr = fopen(singlePath, permission)) != NULL)
{ {
......
...@@ -359,14 +359,14 @@ char *nxagentGetHomePath(void) ...@@ -359,14 +359,14 @@ char *nxagentGetHomePath(void)
#endif #endif
} }
strncpy(nxagentHomeDir, homeEnv, DEFAULT_STRING_LENGTH - 1); snprintf(nxagentHomeDir, DEFAULT_STRING_LENGTH, "%s", homeEnv);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGetHomePath: Assuming NX user's home directory '%s'.\n", nxagentHomeDir); fprintf(stderr, "nxagentGetHomePath: Assuming NX user's home directory '%s'.\n", nxagentHomeDir);
#endif #endif
} }
homePath = (char*) malloc(strlen(nxagentHomeDir) + 1); homePath = strdup(nxagentHomeDir);
if (homePath == NULL) if (homePath == NULL)
{ {
...@@ -377,8 +377,6 @@ char *nxagentGetHomePath(void) ...@@ -377,8 +377,6 @@ char *nxagentGetHomePath(void)
return NULL; return NULL;
} }
strcpy(homePath, nxagentHomeDir);
return homePath; return homePath;
} }
...@@ -434,8 +432,7 @@ char *nxagentGetRootPath(void) ...@@ -434,8 +432,7 @@ char *nxagentGetRootPath(void)
fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory in '%s'.\n", homeEnv); fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory in '%s'.\n", homeEnv);
#endif #endif
strcpy(nxagentRootDir, homeEnv); snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s/.nx", homeEnv);
strcat(nxagentRootDir, "/.nx");
free(homeEnv); free(homeEnv);
...@@ -468,17 +465,17 @@ char *nxagentGetRootPath(void) ...@@ -468,17 +465,17 @@ char *nxagentGetRootPath(void)
return NULL; return NULL;
} }
strcpy(nxagentRootDir, rootEnv); snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s", rootEnv);
} }
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory '%s'.\n", fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory '%s'.\n",
nxagentRootDir); nxagentRootDir);
#endif #endif
} }
rootPath = malloc(strlen(nxagentRootDir) + 1); rootPath = strdup(nxagentRootDir);
if (rootPath == NULL) if (rootPath == NULL)
{ {
...@@ -489,8 +486,6 @@ char *nxagentGetRootPath(void) ...@@ -489,8 +486,6 @@ char *nxagentGetRootPath(void)
return NULL; return NULL;
} }
strcpy(rootPath, nxagentRootDir);
return rootPath; return rootPath;
} }
...@@ -527,9 +522,7 @@ char *nxagentGetSessionPath(void) ...@@ -527,9 +522,7 @@ char *nxagentGetSessionPath(void)
return NULL; return NULL;
} }
strcpy(nxagentSessionDir, rootPath); snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s", rootPath);
free(rootPath);
if (strlen(nxagentSessionDir) + strlen("/C-") + strlen(nxagentSessionId) > DEFAULT_STRING_LENGTH - 1) if (strlen(nxagentSessionDir) + strlen("/C-") + strlen(nxagentSessionId) > DEFAULT_STRING_LENGTH - 1)
{ {
...@@ -538,12 +531,14 @@ char *nxagentGetSessionPath(void) ...@@ -538,12 +531,14 @@ char *nxagentGetSessionPath(void)
nxagentSessionDir); nxagentSessionDir);
#endif #endif
free(rootPath);
return NULL; 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)) if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT))
{ {
...@@ -605,9 +600,7 @@ void nxagentGetClientsPath() ...@@ -605,9 +600,7 @@ void nxagentGetClientsPath()
return; return;
} }
strcpy(nxagentClientsLogName, sessionPath); snprintf(nxagentClientsLogName, DEFAULT_STRING_LENGTH, "%s/clients", sessionPath);
strcat(nxagentClientsLogName, "/clients");
free(sessionPath); free(sessionPath);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment