From 5987a7b1af09e97271be3da74d336a64435e759a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 23 Nov 2017 21:25:26 +0100 Subject: Dialog.c,Display.c,Font.c,NXdixfonts.c: don't use hardcoded string buffer lengths --- nx-X11/programs/Xserver/hw/nxagent/Dialog.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Dialog.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c index b7852a0ac..df6bb1c89 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c @@ -279,15 +279,15 @@ void nxagentLaunchDialog(DialogType dialogType) if (dialogType == DIALOG_FAILED_RECONNECTION) { - strncpy(dialogDisplay, nxagentDisplayName, 255); + strncpy(dialogDisplay, nxagentDisplayName, sizeof(dialogDisplay) - 1); } else { strcpy(dialogDisplay, ":"); - strncat(dialogDisplay, display, 254); + strncat(dialogDisplay, display, sizeof(dialogDisplay) - 1 - 1); } - *(dialogDisplay + 255) = '\0'; + dialogDisplay[sizeof(dialogDisplay) - 1] = '\0'; /* * We don't want to receive SIGCHLD @@ -308,7 +308,7 @@ void nxagentLaunchDialog(DialogType dialogType) DECODE_DIALOG_TYPE(dialogType), *pid, dialogDisplay); #endif - *dialogDisplay = '\0'; + dialogDisplay[0] = '\0'; /* * Restore the previous set of @@ -320,8 +320,7 @@ void nxagentLaunchDialog(DialogType dialogType) void nxagentPulldownDialog(Window wid) { - snprintf(nxagentPulldownWindow, 15, "%ld", (long int) wid); - nxagentPulldownWindow[15] = 0; + snprintf(nxagentPulldownWindow, sizeof(nxagentPulldownWindow), "%ld", (long int) wid); #ifdef TEST fprintf(stderr, "nxagentPulldownDialog: Going to launch pulldown " @@ -330,7 +329,7 @@ void nxagentPulldownDialog(Window wid) nxagentLaunchDialog(DIALOG_PULLDOWN); - nxagentPulldownWindow[0] = 0; + nxagentPulldownWindow[0] = '\0'; } void nxagentFailedReconnectionDialog(int alert, char *error) @@ -372,9 +371,7 @@ void nxagentFailedReconnectionDialog(int alert, char *error) int status; int options = 0; - snprintf(nxagentFailedReconnectionMessage, 255, "Reconnection failed: %s", error); - - *(nxagentFailedReconnectionMessage + 255) = '\0'; + snprintf(nxagentFailedReconnectionMessage, sizeof(nxagentFailedReconnectionMessage), "Reconnection failed: %s", error); nxagentLaunchDialog(DIALOG_FAILED_RECONNECTION); -- cgit v1.2.3 From 4a345786c6ee3b00882f015a7ac7d1d3215c0b9f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 24 Nov 2017 00:25:25 +0100 Subject: Dialog.c,Display.c,NXdixfonts.c: replace strncpy() by snprintf where appropriate --- nx-X11/programs/Xserver/hw/nxagent/Dialog.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Dialog.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c index df6bb1c89..1e394fe38 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c @@ -279,16 +279,13 @@ void nxagentLaunchDialog(DialogType dialogType) if (dialogType == DIALOG_FAILED_RECONNECTION) { - strncpy(dialogDisplay, nxagentDisplayName, sizeof(dialogDisplay) - 1); + snprintf(dialogDisplay, sizeof(dialogDisplay), "%s", nxagentDisplayName); } else { - strcpy(dialogDisplay, ":"); - strncat(dialogDisplay, display, sizeof(dialogDisplay) - 1 - 1); + snprintf(dialogDisplay, sizeof(dialogDisplay), ":%s", display); } - dialogDisplay[sizeof(dialogDisplay) - 1] = '\0'; - /* * We don't want to receive SIGCHLD * before we store the child pid. -- cgit v1.2.3 From ea1e0bea3c41f5c8ad8fc3e22ecd8f2d44e82685 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 2 Jan 2018 19:23:20 +0100 Subject: Replace hardcoded string lengths by macros --- nx-X11/programs/Xserver/hw/nxagent/Dialog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Dialog.c') 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); -- cgit v1.2.3