aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2018-01-02 19:24:49 +0100
committerUlrich Sibiller <uli42@gmx.de>2018-01-07 01:27:07 +0100
commit19a3918a7216ac1006bdfd96239fafc6eb97d523 (patch)
tree3a3e8f74840ce1ea8c6153ca7e8bb86b1f78563e
parentea1e0bea3c41f5c8ad8fc3e22ecd8f2d44e82685 (diff)
downloadnx-libs-19a3918a7216ac1006bdfd96239fafc6eb97d523.tar.gz
nx-libs-19a3918a7216ac1006bdfd96239fafc6eb97d523.tar.bz2
nx-libs-19a3918a7216ac1006bdfd96239fafc6eb97d523.zip
Display.c: pass down buffer size to nxagentLookForIconFile
Also comment the code and convert error messages to warnings.
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Display.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c
index c9c2f4e7a..b78530e37 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Display.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c
@@ -1815,12 +1815,10 @@ FIXME: Is this needed?
}
static FILE *nxagentLookForIconFile(char *iconName, const char *permission,
- char *return_path)
+ char *return_path, int return_path_size)
{
char *path;
- char *end;
char singlePath[PATH_MAX];
- int breakLoop;
FILE *fptr = NULL;
#ifdef WIN32
@@ -1836,56 +1834,56 @@ static FILE *nxagentLookForIconFile(char *iconName, const char *permission,
return NULL;
}
- for(breakLoop = 0; breakLoop == 0 && fptr == NULL; )
+ for (int breakLoop = False; breakLoop == False && fptr == NULL; )
{
- end = strchr(path, separator);
+ char *end = strchr(path, separator);
+ /* separator found */
if (end != NULL)
{
if ((end - path) > sizeof(singlePath) - 1)
{
- fprintf(stderr, "Warning: Path too long - ignored.\n");
+ fprintf(stderr, "Warning: PATH component too long - ignoring it.\n");
path = end + 1;
continue;
}
- strncpy(singlePath, path, (unsigned long)(end - path));
-
- singlePath[(unsigned long)(end - path)] = '\0';
-
+ snprintf(singlePath, (unsigned long)(end - path + 1), "%s", path);
path = end + 1;
}
else
{
if (strlen(path) > sizeof(singlePath) - 1)
{
- fprintf(stderr, "Error: Path too long.\n");
+ fprintf(stderr, "Warning: PATH component too long - ignoring it.\n");
return NULL;
}
- strcpy(singlePath, path);
+ snprintf(singlePath, sizeof(singlePath), "%s", path);
- breakLoop = 1;
+ breakLoop = True;
}
- if (singlePath[strlen(singlePath)- 1] == slash[0])
+ /* cut off trailing slashes, if any */
+ while (singlePath[strlen(singlePath) - 1] == slash[0])
{
- singlePath[strlen(singlePath)- 1] = '\0';
+ singlePath[strlen(singlePath) - 1] = '\0';
}
- if (strlen(singlePath) + strlen(iconName) + 1 < sizeof(singlePath)<)
+ /* append slash and icon name */
+ if (strlen(singlePath) + strlen(iconName) + 1 < sizeof(singlePath))
{
strncat(singlePath, slash, 1);
strcat(singlePath, iconName);
if ((fptr = fopen(singlePath, permission)) != NULL)
{
- strcpy(return_path, singlePath);
+ snprintf(return_path, return_path_size, "%s", singlePath);
}
}
else
{
- fprintf(stderr, "Error: Path too long.\n");
+ fprintf(stderr, "Warning: Icon path too long.\n");
}
}
@@ -1909,13 +1907,13 @@ Bool nxagentMakeIcon(Display *display, Pixmap *nxIcon, Pixmap *nxMask)
*/
if(nxagentX2go)
{
- agent_icon_name=X2GOAGENT_ICON_NAME;
- agentIconData=x2goagentIconData;
+ agent_icon_name = X2GOAGENT_ICON_NAME;
+ agentIconData = x2goagentIconData;
}
else
{
- agent_icon_name=NXAGENT_ICON_NAME;
- agentIconData=nxagentIconData;
+ agent_icon_name = NXAGENT_ICON_NAME;
+ agentIconData = nxagentIconData;
}
/* FIXME: use a compile time define here, /usr/NX is a nomachine path */
@@ -1923,7 +1921,7 @@ Bool nxagentMakeIcon(Display *display, Pixmap *nxIcon, Pixmap *nxMask)
if ((icon_fp = fopen(default_path, "r")) == NULL)
{
- icon_fp = nxagentLookForIconFile(agent_icon_name, "r", icon_path);
+ icon_fp = nxagentLookForIconFile(agent_icon_name, "r", icon_path, sizeof(icon_path));
if (icon_fp != NULL)
{
@@ -1935,7 +1933,7 @@ Bool nxagentMakeIcon(Display *display, Pixmap *nxIcon, Pixmap *nxMask)
{
fclose (icon_fp);
success = True;
- strcpy(icon_path, default_path);
+ snprintf(icon_path, sizeof(icon_path), "%s", default_path);
}
if (success)