aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Args.c71
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Args.h16
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Dialog.c8
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Dialog.h6
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Display.c2
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c9
6 files changed, 43 insertions, 69 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c
index cccfd40e0..8ee64ba75 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Args.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c
@@ -126,15 +126,15 @@ extern char dispatchExceptionAtReset;
extern const char *__progname;
-char nxagentDisplayName[1024];
+char nxagentDisplayName[NXAGENTDISPLAYNAMELENGTH];
Bool nxagentSynchronize = False;
Bool nxagentRealWindowProp = False;
-char nxagentShadowDisplayName[1024] = {0};
+char nxagentShadowDisplayName[NXAGENTSHADOWDISPLAYNAMELENGTH] = {0};
-char nxagentWindowName[256];
-char nxagentDialogName[256];
-char nxagentSessionId[256] = {0};
+char nxagentWindowName[NXAGENTWINDOWNAMELENGTH];
+char nxagentDialogName[NXAGENTDIALOGNAMELENGTH];
+char nxagentSessionId[NXAGENTSESSIONIDLENGTH] = {0};
char *nxagentOptionsFilenameOrString;
Bool nxagentFullGeneration = False;
@@ -326,10 +326,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
if (++i < argc)
{
- strncpy(nxagentDisplayName, argv[i], 1023);
-
- nxagentDisplayName[1023] = '\0';
-
+ snprintf(nxagentDisplayName, NXAGENTDISPLAYNAMELENGTH, "%s", argv[i]);
return 2;
}
@@ -340,10 +337,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
if (++i < argc)
{
- strncpy(nxagentSessionId, argv[i], 255);
-
- *(nxagentSessionId + 255) = '\0';
-
+ snprintf(nxagentSessionId, NXAGENTSESSIONIDLENGTH, "%s", argv[i]);
return 2;
}
@@ -360,35 +354,13 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
if (++i < argc)
{
- int size;
-
free(nxagentOptionsFilenameOrString);
nxagentOptionsFilenameOrString = NULL;
- if ((size = strlen(argv[i])) < 1024)
+ if (-1 == asprintf(&nxagentOptionsFilenameOrString, "%s", argv[i]))
{
- if ((nxagentOptionsFilenameOrString = malloc(size + 1)) == NULL)
- {
- FatalError("malloc failed");
- }
-
- strncpy(nxagentOptionsFilenameOrString, argv[i], size);
-
- nxagentOptionsFilenameOrString[size] = '\0';
+ FatalError("malloc failed");
}
- else
- {
- /*
- * It is useless to store the file name
- * that has just been truncated.
- */
-
- #ifdef WARNING
- fprintf(stderr, "ddxProcessArgument: WARNING! Option file name "
- "too long. It will be ignored.\n");
- #endif
- }
-
return 2;
}
@@ -670,10 +642,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
if (++i < argc)
{
- strncpy(nxagentWindowName, argv[i], 255);
-
- *(nxagentWindowName + 255) = '\0';
-
+ snprintf(nxagentWindowName, NXAGENTWINDOWNAMELENGTH, "%s", argv[i]);
return 2;
}
@@ -903,15 +872,13 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
if (++i < argc)
{
- strncpy(nxagentShadowDisplayName, argv[i], 1023);
+ snprintf(nxagentShadowDisplayName, NXAGENTSHADOWDISPLAYNAMELENGTH, "%s", argv[i]);
if (strcmp(nxagentShadowDisplayName, "") == 0)
{
FatalError("Invalid shadow display option");
}
- *(nxagentShadowDisplayName + 1023) = '\0';
-
return 2;
}
@@ -1780,9 +1747,7 @@ N/A
if (*nxagentWindowName == '\0')
{
- strncpy(nxagentWindowName, "NX", 255);
-
- *(nxagentWindowName + 255) = '\0';
+ snprintf(nxagentWindowName, NXAGENTWINDOWNAMELENGTH, "NX");
}
/*
@@ -2161,9 +2126,7 @@ void ddxUseMsg()
static int nxagentGetDialogName()
{
- strcpy(nxagentDialogName, "NX");
-
- *(nxagentDialogName + 255) = '\0';
+ snprintf(nxagentDialogName, NXAGENTDIALOGNAMELENGTH, "NX");
if (*nxagentSessionId != '\0')
{
@@ -2171,17 +2134,19 @@ static int nxagentGetDialogName()
strcpy(nxagentDialogName, "NX - ");
+ /* if the session id contains an MD5 hash in a well-known format cut it off */
if (length > (MD5_LENGTH * 2 + 1) &&
*(nxagentSessionId + (length - (MD5_LENGTH * 2 + 1))) == '-')
{
- strncat(nxagentDialogName, nxagentSessionId, length - (MD5_LENGTH * 2 + 1));
+ strncat(nxagentDialogName, nxagentSessionId,
+ MIN(NXAGENTDIALOGNAMELENGTH - strlen(nxagentDialogName), length - (MD5_LENGTH * 2 + 1)) - 1);
}
else
{
- strncat(nxagentDialogName, nxagentSessionId, 250);
+ strncat(nxagentDialogName, nxagentSessionId, NXAGENTDIALOGNAMELENGTH - strlen(nxagentDialogName) - 1);
}
- *(nxagentSessionId + 255) = '\0';
+ nxagentDialogName[NXAGENTDIALOGNAMELENGTH - 1] = '\0';
return 1;
}
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.h b/nx-X11/programs/Xserver/hw/nxagent/Args.h
index 0bfc44a93..a3f7e349b 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Args.h
+++ b/nx-X11/programs/Xserver/hw/nxagent/Args.h
@@ -52,11 +52,17 @@ struct UserGeometry{
extern Bool nxagentUseNXTrans;
-extern char nxagentSessionId[];
-extern char nxagentDisplayName[1024];
-extern char nxagentShadowDisplayName[];
-extern char nxagentWindowName[];
-extern char nxagentDialogName[];
+#define NXAGENTSESSIONIDLENGTH 256
+#define NXAGENTDISPLAYNAMELENGTH 1024
+#define NXAGENTSHADOWDISPLAYNAMELENGTH 1024
+#define NXAGENTWINDOWNAMELENGTH 256
+#define NXAGENTDIALOGNAMELENGTH 256
+
+extern char nxagentSessionId[NXAGENTSESSIONIDLENGTH];
+extern char nxagentDisplayName[NXAGENTDISPLAYNAMELENGTH];
+extern char nxagentShadowDisplayName[NXAGENTSHADOWDISPLAYNAMELENGTH];
+extern char nxagentWindowName[NXAGENTWINDOWNAMELENGTH];
+extern char nxagentDialogName[NXAGENTDIALOGNAMELENGTH];
extern Bool nxagentSynchronize;
extern Bool nxagentRealWindowProp;
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c
index 1e394fe38..c09618693 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c
@@ -66,9 +66,9 @@ int nxagentDisableDeferModePid = 0;
static int nxagentFailedReconnectionDialogPid = 0;
-char nxagentPulldownWindow[16];
+char nxagentPulldownWindow[NXAGENTPULLDOWNWINDOWLENGTH];
-char nxagentFailedReconnectionMessage[256];
+char nxagentFailedReconnectionMessage[NXAGENTFAILEDRECONNECTIONMESSAGELENGTH];
void nxagentResetDialog(int pid)
{
@@ -317,7 +317,7 @@ void nxagentLaunchDialog(DialogType dialogType)
void nxagentPulldownDialog(Window wid)
{
- snprintf(nxagentPulldownWindow, sizeof(nxagentPulldownWindow), "%ld", (long int) wid);
+ snprintf(nxagentPulldownWindow, NXAGENTPULLDOWNWINDOWLENGTH, "%ld", (long int) wid);
#ifdef TEST
fprintf(stderr, "nxagentPulldownDialog: Going to launch pulldown "
@@ -368,7 +368,7 @@ void nxagentFailedReconnectionDialog(int alert, char *error)
int status;
int options = 0;
- snprintf(nxagentFailedReconnectionMessage, sizeof(nxagentFailedReconnectionMessage), "Reconnection failed: %s", error);
+ snprintf(nxagentFailedReconnectionMessage, NXAGENTFAILEDRECONNECTIONMESSAGELENGTH, "Reconnection failed: %s", error);
nxagentLaunchDialog(DIALOG_FAILED_RECONNECTION);
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.h b/nx-X11/programs/Xserver/hw/nxagent/Dialog.h
index 133dee242..ffcdf48f2 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.h
+++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.h
@@ -55,9 +55,11 @@ extern int nxagentDisableRandRModeDialogPid;
extern int nxagentEnableDeferModePid;
extern int nxagentDisableDeferModePid;
-extern char nxagentFailedReconnectionMessage[];
+#define NXAGENTFAILEDRECONNECTIONMESSAGELENGTH 256
+extern char nxagentFailedReconnectionMessage[NXAGENTFAILEDRECONNECTIONMESSAGELENGTH];
-extern char nxagentPulldownWindow[];
+#define NXAGENTPULLDOWNWINDOWLENGTH 16
+extern char nxagentPulldownWindow[NXAGENTPULLDOWNWINDOWLENGTH];
extern void nxagentLaunchDialog(DialogType type);
extern void nxagentResetDialog(int pid);
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c
index d4e032046..c9c2f4e7a 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Display.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c
@@ -1150,7 +1150,7 @@ void nxagentOpenDisplay(int argc, char *argv[])
if (*nxagentDisplayName == '\0')
{
- snprintf(nxagentDisplayName, sizeof(nxagentDisplayName), "%s", XDisplayName(NULL));
+ snprintf(nxagentDisplayName, NXAGENTDISPLAYNAMELENGTH, "%s", XDisplayName(NULL));
}
nxagentCloseDisplay();
diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c
index 563dacd92..e59144f94 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c
@@ -96,7 +96,8 @@ static Bool doListFontsAndAliases(ClientPtr client, LFclosurePtr c);
#ifdef NX_TRANS_SOCKET
-char _NXFontPath[1024];
+#define NXFONTPATHLENGTH 1024
+char _NXFontPath[NXFONTPATHLENGTH];
/*
* Override the default font path and make
@@ -121,7 +122,7 @@ static const char *_NXGetFontPath(const char *path)
if (fontEnv != NULL && *fontEnv != '\0')
{
- if (strlen(fontEnv) + 1 > sizeof(_NXFontPath))
+ if (strlen(fontEnv) + 1 > NXFONTPATHLENGTH)
{
#ifdef NX_TRANS_TEST
fprintf(stderr, "_NXGetFontPath: WARNING! Maximum length of font path exceeded.\n");
@@ -129,7 +130,7 @@ static const char *_NXGetFontPath(const char *path)
goto _NXGetFontPathError;
}
- strcpy(_NXFontPath, fontEnv);
+ snprintf(_NXFontPath, NXFONTPATHLENGTH, "%s", fontEnv);
#ifdef NX_TRANS_TEST
fprintf(stderr, "_NXGetFontPath: Using NX font path [%s].\n", _NXFontPath);
@@ -140,7 +141,7 @@ static const char *_NXGetFontPath(const char *path)
_NXGetFontPathError:
- snprintf(_NXFontPath, sizeof(_NXFontPath), "%s", path);
+ snprintf(_NXFontPath, NXFONTPATHLENGTH, "%s", path);
#ifdef NX_TRANS_TEST
fprintf(stderr, "_NXGetFontPath: Using default font path [%s].\n", _NXFontPath);