[X2Go-Commits] [nx-libs] 11/29: Display.c: pass down buffer size to nxagentLookForIconFile
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 19a3918a7216ac1006bdfd96239fafc6eb97d523
Author: Ulrich Sibiller <uli42 at gmx.de>
Date: Tue Jan 2 19:24:49 2018 +0100
Display.c: pass down buffer size to nxagentLookForIconFile
Also comment the code and convert error messages to warnings.
---
nx-X11/programs/Xserver/hw/nxagent/Display.c | 46 +++++++++++++---------------
1 file 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 c9c2f4e..b78530e 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)
--
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